~launchpad-pqm/launchpad/devel

13211.1.1 by Jeroen Vermeulen
Lint.
1
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.17 by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/.
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
4
"""queue tool base class tests."""
5
6
__metaclass__ = type
10293.1.1 by Barry Warsaw, Max Bowsher
Switch from using sha and md5 to hashlib. Also use hashlib.sha256 instead of
7
8
import hashlib
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
9
import os
10
import shutil
11545.2.1 by Julian Edwards
add failing test
11
from StringIO import StringIO
3500.3.46 by Celso Providelo
review comments, r=spiv
12
import tempfile
13277.2.2 by Jeroen Vermeulen
Fix the upload tag in the queue script for copy-job uploads.
13
from testtools.matchers import StartsWith
13211.1.1 by Jeroen Vermeulen
Lint.
14
from unittest import TestCase
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
15
16
from zope.component import getUtility
11545.2.3 by Julian Edwards
Tim's review comments and other improvements
17
from zope.security.interfaces import ForbiddenAttribute
4376.2.52 by Julian Edwards
Pre-publication overrides of source packages should abort if the override
18
from zope.security.proxy import removeSecurityProxy
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
19
20
from canonical.config import config
5842.1.1 by James Henstridge
Rename the transaction isolation level constants to match the psycopg2
21
from canonical.database.sqlbase import ISOLATION_LEVEL_READ_COMMITTED
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
22
from canonical.launchpad.database.librarian import LibraryFileAlias
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
23
from canonical.launchpad.interfaces.librarian import ILibraryFileAliasSet
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
24
from canonical.launchpad.interfaces.lpstorm import IStore
13211.1.1 by Jeroen Vermeulen
Lint.
25
from canonical.librarian.testing.server import fillLibrarianFile
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
26
from canonical.librarian.utils import filechunks
11666.3.5 by Curtis Hovey
Import layers from canonical.testing.layers.
27
from canonical.testing.layers import (
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
28
    DatabaseFunctionalLayer,
11545.2.1 by Julian Edwards
add failing test
29
    LaunchpadZopelessLayer,
11737.4.1 by Robert Collins
Finish transitioning LibrarianTestSetup to LibrarianServerFixture, drop the singleton. \o/
30
    LibrarianLayer,
11545.2.1 by Julian Edwards
add failing test
31
    )
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
32
from lp.archiveuploader.nascentupload import NascentUpload
33
from lp.archiveuploader.tests import (
34
    datadir,
35
    getPolicy,
36
    insertFakeChangesFileForAllPackageUploads,
37
    )
8523.3.1 by Gavin Panella
Bugs tree reorg after automated migration.
38
from lp.bugs.interfaces.bug import IBugSet
11545.2.1 by Julian Edwards
add failing test
39
from lp.bugs.interfaces.bugtask import (
40
    BugTaskStatus,
41
    IBugTaskSet,
42
    )
8294.6.1 by Julian Edwards
First stab at code-reorg. Still got a discrepancy on stuff I assigned to registry but not migrated yet.
43
from lp.registry.interfaces.distribution import IDistributionSet
44
from lp.registry.interfaces.person import IPersonSet
9113.7.7 by Jonathan Lange
Update all the rest of the imports of PackagePublishingPocket.
45
from lp.registry.interfaces.pocket import PackagePublishingPocket
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
46
from lp.registry.interfaces.series import SeriesStatus
12070.1.37 by Tim Penhey
Remove mock_logger and mock_logger_quiet.
47
from lp.services.log.logger import DevNullLogger
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
48
from lp.services.mail import stub
11411.6.9 by Julian Edwards
Move PackageUploadStatus and PackageUploadCustomFormat
49
from lp.soyuz.enums import (
50
    ArchivePurpose,
11411.6.12 by Julian Edwards
Move PackagePublishingStatus/Priority
51
    PackagePublishingStatus,
11411.6.9 by Julian Edwards
Move PackageUploadStatus and PackageUploadCustomFormat
52
    PackageUploadStatus,
53
    )
13211.1.1 by Jeroen Vermeulen
Lint.
54
from lp.soyuz.interfaces.archive import IArchiveSet
55
from lp.soyuz.interfaces.queue import IPackageUploadSet
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
56
from lp.soyuz.model.queue import PackageUploadBuild
11545.2.1 by Julian Edwards
add failing test
57
from lp.soyuz.scripts.processaccepted import (
58
    close_bugs_for_sourcepackagerelease,
59
    )
8294.6.1 by Julian Edwards
First stab at code-reorg. Still got a discrepancy on stuff I assigned to registry but not migrated yet.
60
from lp.soyuz.scripts.queue import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
61
    CommandRunner,
62
    CommandRunnerError,
63
    name_queue_map,
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
64
    QueueAction,
13382.3.1 by Julian Edwards
Add a failing test to check setting overrides from the queue script.
65
    QueueActionOverride
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
66
    )
11545.2.1 by Julian Edwards
add failing test
67
from lp.testing import (
11545.2.3 by Julian Edwards
Tim's review comments and other improvements
68
    celebrity_logged_in,
11545.2.1 by Julian Edwards
add failing test
69
    person_logged_in,
70
    TestCaseWithFactory,
71
    )
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
72
from lp.testing.fakemethod import FakeMethod
73
74
75
class TestQueueBase:
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
76
    """Base methods for queue tool test classes."""
77
3691.357.9 by Stuart Bishop
Make test_queue.py tests connect as the correct database user
78
    def setUp(self):
3691.357.11 by Stuart Bishop
Fix transaction isolation issues in test_queue created now that the Librarian can update LibraryFileAlias rows
79
        # Switch database user and set isolation level to READ COMMIITTED
80
        # to avoid SERIALIZATION exceptions with the Librarian.
81
        LaunchpadZopelessLayer.alterConnection(
82
                dbuser=self.dbuser,
5842.1.1 by James Henstridge
Rename the transaction isolation level constants to match the psycopg2
83
                isolation=ISOLATION_LEVEL_READ_COMMITTED)
3691.357.9 by Stuart Bishop
Make test_queue.py tests connect as the correct database user
84
3500.3.41 by Celso Providelo
review comments, r=spiv
85
    def _test_display(self, text):
86
        """Store output from queue tool for inspection."""
87
        self.test_output.append(text)
88
89
    def execute_command(self, argument, queue_name='new', no_mail=True,
13144.1.2 by Steve Kowalik
Remove announcelist from upload policy, its tests, the queue tool and its
90
                        distribution_name='ubuntu', component_name=None,
91
                        section_name=None, priority_name=None,
92
                        suite_name='breezy-autotest', quiet=True):
3500.3.41 by Celso Providelo
review comments, r=spiv
93
        """Helper method to execute a queue command.
94
13194.2.1 by Gavin Panella
Change all uses of 'initialise' to 'initialize'.
95
        Initialize output buffer and execute a command according
3500.3.41 by Celso Providelo
review comments, r=spiv
96
        given argument.
97
98
        Return the used QueueAction instance.
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
99
        """
3500.3.41 by Celso Providelo
review comments, r=spiv
100
        self.test_output = []
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
101
        queue = name_queue_map[queue_name]
3500.3.41 by Celso Providelo
review comments, r=spiv
102
        runner = CommandRunner(
13144.1.2 by Steve Kowalik
Remove announcelist from upload policy, its tests, the queue tool and its
103
            queue, distribution_name, suite_name, no_mail,
4500.1.4 by Julian Edwards
First batch of tests added.
104
            component_name, section_name, priority_name,
3500.3.41 by Celso Providelo
review comments, r=spiv
105
            display=self._test_display)
106
107
        return runner.execute(argument.split())
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
108
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
109
    def assertEmail(self, expected_to_addrs):
110
        """Pop an email from the stub queue and check its recipients."""
111
        from_addr, to_addrs, raw_msg = stub.test_emails.pop()
112
        self.assertEqual(to_addrs, expected_to_addrs)
113
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
114
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
115
class TestQueueTool(TestQueueBase, TestCase):
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
116
    layer = LaunchpadZopelessLayer
117
    dbuser = config.uploadqueue.dbuser
118
119
    def setUp(self):
120
        """Create contents in disk for librarian sampledata."""
4898.1.2 by Julian Edwards
Apply intellectronica and bac's review comments.
121
        # Packageupload.notify() needs real changes file data to send
122
        # email, so this nice simple "ed" changes file will do.  It's
123
        # the /wrong/ changes file for the package in the upload queue,
124
        # but that doesn't matter as only email addresses are parsed out
125
        # of it.
5094.3.8 by Julian Edwards
Add more tests and cleanup per mwh review.
126
        insertFakeChangesFileForAllPackageUploads()
6269.10.12 by Celso Providelo
Fixing test failures.
127
        fake_chroot = LibraryFileAlias.get(1)
128
129
        LaunchpadZopelessLayer.switchDbUser("testadmin")
130
131
        ubuntu = getUtility(IDistributionSet)['ubuntu']
132
        breezy_autotest = ubuntu.getSeries('breezy-autotest')
133
        breezy_autotest['i386'].addOrUpdateChroot(fake_chroot)
134
135
        LaunchpadZopelessLayer.txn.commit()
136
        LaunchpadZopelessLayer.switchDbUser('launchpad')
137
3691.357.9 by Stuart Bishop
Make test_queue.py tests connect as the correct database user
138
        TestQueueBase.setUp(self)
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
139
140
    def tearDown(self):
141
        """Remove test contents from disk."""
11737.4.1 by Robert Collins
Finish transitioning LibrarianTestSetup to LibrarianServerFixture, drop the singleton. \o/
142
        LibrarianLayer.librarian_fixture.clear()
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
143
5508.1.2 by Julian Edwards
Apply intellectronica's review style comments.
144
    def uploadPackage(self,
145
            changesfile="suite/bar_1.0-1/bar_1.0-1_source.changes"):
5508.1.1 by Julian Edwards
When accepting single source uploads that are unknown (ie. new packages),
146
        """Helper function to upload a package."""
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
147
        LaunchpadZopelessLayer.switchDbUser("uploader")
5508.1.1 by Julian Edwards
When accepting single source uploads that are unknown (ie. new packages),
148
        sync_policy = getPolicy(
149
            name='sync', distro='ubuntu', distroseries='breezy-autotest')
11204.5.14 by William Grant
Remove conditional from NascentUpload.__init__. NU.from_changesfile_path should now be used if the ChangesFile must be created too.
150
        bar_src = NascentUpload.from_changesfile_path(
5508.1.1 by Julian Edwards
When accepting single source uploads that are unknown (ie. new packages),
151
            datadir(changesfile),
12070.1.37 by Tim Penhey
Remove mock_logger and mock_logger_quiet.
152
            sync_policy, DevNullLogger())
5508.1.1 by Julian Edwards
When accepting single source uploads that are unknown (ie. new packages),
153
        bar_src.process()
154
        bar_src.do_accept()
155
        LaunchpadZopelessLayer.txn.commit()
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
156
        LaunchpadZopelessLayer.switchDbUser(self.dbuser)
5508.1.1 by Julian Edwards
When accepting single source uploads that are unknown (ie. new packages),
157
        return bar_src
158
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
159
    def testBrokenAction(self):
160
        """Check if an unknown action raises CommandRunnerError."""
161
        self.assertRaises(
3500.3.41 by Celso Providelo
review comments, r=spiv
162
            CommandRunnerError, self.execute_command, 'foo')
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
163
3500.3.44 by Celso Providelo
fix queue tool help action and add extra tests
164
    def testHelpAction(self):
165
        """Check if help is working properly.
166
167
        Without arguments 'help' should return the docstring summary of
168
        all available actions.
169
170
        Optionally we can pass arguments corresponding to the specific
171
        actions we want to see the help, not available actions will be
172
        reported.
173
        """
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
174
        self.execute_command('help')
3500.3.44 by Celso Providelo
fix queue tool help action and add extra tests
175
        self.assertEqual(
176
            ['Running: "help"',
177
             '\tinfo : Present the Queue item including its contents. ',
178
             '\taccept : Accept the contents of a queue item. ',
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
179
             '\treport : Present a report about the size of available '
180
                  'queues ',
3500.3.44 by Celso Providelo
fix queue tool help action and add extra tests
181
             '\treject : Reject the contents of a queue item. ',
182
             '\toverride : Override information in a queue item content. ',
183
             '\tfetch : Fetch the contents of a queue item. '],
184
            self.test_output)
185
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
186
        self.execute_command('help fetch')
3500.3.44 by Celso Providelo
fix queue tool help action and add extra tests
187
        self.assertEqual(
188
            ['Running: "help fetch"',
189
             '\tfetch : Fetch the contents of a queue item. '],
190
            self.test_output)
191
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
192
        self.execute_command('help foo')
3500.3.44 by Celso Providelo
fix queue tool help action and add extra tests
193
        self.assertEqual(
194
            ['Running: "help foo"',
195
             'Not available action(s): foo'],
196
            self.test_output)
197
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
198
    def testInfoAction(self):
199
        """Check INFO queue action without arguments present all items."""
3500.3.41 by Celso Providelo
review comments, r=spiv
200
        queue_action = self.execute_command('info')
201
        # check if the considered queue size matches the existent number
202
        # of records in sampledata
203
        bat = getUtility(IDistributionSet)['ubuntu']['breezy-autotest']
3691.441.21 by Malcolm Cleaton
More stuff
204
        queue_size = getUtility(IPackageUploadSet).count(
13211.1.1 by Jeroen Vermeulen
Lint.
205
            status=PackageUploadStatus.NEW, distroseries=bat,
206
            pocket=PackagePublishingPocket.RELEASE)
3500.3.41 by Celso Providelo
review comments, r=spiv
207
        self.assertEqual(queue_size, queue_action.size)
208
        # check if none of them was filtered, since not filter term
209
        # was passed.
210
        self.assertEqual(queue_size, queue_action.items_size)
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
211
3147.5.48 by Celso Providelo
post-commit review comments, r=spiv
212
    def testInfoActionDoesNotSupportWildCards(self):
213
        """Check if an wildcard-like filter raises CommandRunnerError."""
214
        self.assertRaises(
215
            CommandRunnerError, self.execute_command, 'info *')
216
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
217
    def testInfoActionByID(self):
3147.5.48 by Celso Providelo
post-commit review comments, r=spiv
218
        """Check INFO queue action filtering by ID.
219
220
        It should work as expected in case of existent ID in specified the
221
        location.
222
        Otherwise it raises CommandRunnerError if:
223
         * ID not found
224
         * specified ID doesn't match given suite name
225
         * specified ID doesn't match the queue name
226
        """
3500.3.41 by Celso Providelo
review comments, r=spiv
227
        queue_action = self.execute_command('info 1')
4500.1.4 by Julian Edwards
First batch of tests added.
228
        # Check if only one item was retrieved.
3500.3.41 by Celso Providelo
review comments, r=spiv
229
        self.assertEqual(1, queue_action.items_size)
230
231
        displaynames = [item.displayname for item in queue_action.items]
232
        self.assertEqual(['mozilla-firefox'], displaynames)
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
233
4500.1.4 by Julian Edwards
First batch of tests added.
234
        # Check passing multiple IDs.
235
        queue_action = self.execute_command('info 1 3 4')
236
        self.assertEqual(3, queue_action.items_size)
237
        [mozilla, netapplet, alsa] = queue_action.items
238
        self.assertEqual('mozilla-firefox', mozilla.displayname)
239
        self.assertEqual('netapplet', netapplet.displayname)
240
        self.assertEqual('alsa-utils', alsa.displayname)
241
242
        # Check not found ID.
3147.5.48 by Celso Providelo
post-commit review comments, r=spiv
243
        self.assertRaises(
244
            CommandRunnerError, self.execute_command, 'info 100')
245
4500.1.4 by Julian Edwards
First batch of tests added.
246
        # Check looking in the wrong suite.
3147.5.48 by Celso Providelo
post-commit review comments, r=spiv
247
        self.assertRaises(
3147.5.50 by Celso Providelo
post-merge review, r=spiv
248
            CommandRunnerError, self.execute_command, 'info 1',
249
            suite_name='breezy-autotest-backports')
3147.5.48 by Celso Providelo
post-commit review comments, r=spiv
250
4500.1.4 by Julian Edwards
First batch of tests added.
251
        # Check looking in the wrong queue.
3147.5.48 by Celso Providelo
post-commit review comments, r=spiv
252
        self.assertRaises(
3147.5.50 by Celso Providelo
post-merge review, r=spiv
253
            CommandRunnerError, self.execute_command, 'info 1',
254
            queue_name='done')
3147.5.48 by Celso Providelo
post-commit review comments, r=spiv
255
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
256
    def testInfoActionByName(self):
257
        """Check INFO queue action filtering by name"""
3500.3.41 by Celso Providelo
review comments, r=spiv
258
        queue_action = self.execute_command('info pmount')
259
        # check if only one item was retrieved as expected in the current
260
        # sampledata
261
        self.assertEqual(1, queue_action.items_size)
262
263
        displaynames = [item.displayname for item in queue_action.items]
264
        self.assertEqual(['pmount'], displaynames)
265
4500.1.4 by Julian Edwards
First batch of tests added.
266
        # Check looking for multiple names.
267
        queue_action = self.execute_command('info pmount alsa-utils')
268
        self.assertEqual(2, queue_action.items_size)
269
        [pmount, alsa] = queue_action.items
270
        self.assertEqual('pmount', pmount.displayname)
271
        self.assertEqual('alsa-utils', alsa.displayname)
272
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
273
    def testAcceptingSourceGeneratesEmail(self):
274
        """Check if accepting a source package generates an email."""
5434.1.1 by Julian Edwards
Add/fix tests.
275
        # We need to upload a new source package to do this because the
276
        # sample data is horribly broken with published sources also in
277
        # the NEW queue.  Doing it this way guarantees a nice set of data.
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
278
        self.uploadPackage()
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
279
5434.1.1 by Julian Edwards
Add/fix tests.
280
        # Swallow email generated at the upload stage.
281
        stub.test_emails.pop()
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
282
283
        # Add a chroot to breezy-autotest/i386, so the system can create
284
        # builds for it.
285
        LaunchpadZopelessLayer.txn.commit()
286
        LaunchpadZopelessLayer.switchDbUser("launchpad")
287
288
        a_file = getUtility(ILibraryFileAliasSet)[1]
289
        breezy_autotest = getUtility(
290
            IDistributionSet)['ubuntu']['breezy-autotest']
291
        breezy_autotest['i386'].addOrUpdateChroot(a_file)
292
293
        LaunchpadZopelessLayer.txn.commit()
294
        LaunchpadZopelessLayer.switchDbUser(self.dbuser)
295
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
296
        queue_action = self.execute_command(
5434.1.1 by Julian Edwards
Add/fix tests.
297
            'accept bar', no_mail=False)
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
298
        self.assertEqual(1, queue_action.items_size)
5313.2.5 by Julian Edwards
Fix an unrelated test that now produces two emails.
299
        self.assertEqual(2, len(stub.test_emails))
300
        # Emails sent are the announcement and the uploader's notification:
301
        self.assertEmail(['autotest_changes@ubuntu.com'])
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
302
        self.assertEmail(
303
            ['Daniel Silverstone <daniel.silverstone@canonical.com>'])
304
5871.1.1 by Celso Providelo
Create build record when accepting new sources using queue-tool.
305
    def testAcceptingSourceCreateBuilds(self):
306
        """Check if accepting a source package creates build records."""
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
307
        self.uploadPackage()
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
308
5871.1.1 by Celso Providelo
Create build record when accepting new sources using queue-tool.
309
        # Swallow email generated at the upload stage.
310
        stub.test_emails.pop()
6128.3.5 by Celso Providelo
Fixing test failures.
311
312
        # Add a chroot to breezy-autotest/i386, so the system can create
313
        # builds for it.
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
314
        LaunchpadZopelessLayer.txn.commit()
315
        LaunchpadZopelessLayer.switchDbUser("launchpad")
316
6128.3.5 by Celso Providelo
Fixing test failures.
317
        a_file = getUtility(ILibraryFileAliasSet)[1]
318
        breezy_autotest = getUtility(
319
            IDistributionSet)['ubuntu']['breezy-autotest']
320
        breezy_autotest['i386'].addOrUpdateChroot(a_file)
321
5871.1.1 by Celso Providelo
Create build record when accepting new sources using queue-tool.
322
        LaunchpadZopelessLayer.txn.commit()
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
323
        LaunchpadZopelessLayer.switchDbUser(self.dbuser)
5871.1.1 by Celso Providelo
Create build record when accepting new sources using queue-tool.
324
325
        queue_action = self.execute_command(
326
            'accept bar', no_mail=False)
327
        self.assertEqual(1, queue_action.items_size)
328
        self.assertEqual(2, len(stub.test_emails))
329
330
        [queue_item] = queue_action.items
331
        [queue_source] = queue_item.sources
332
        sourcepackagerelease = queue_source.sourcepackagerelease
333
        [build] = sourcepackagerelease.builds
334
        self.assertEqual(
335
            'i386 build of bar 1.0-1 in ubuntu breezy-autotest RELEASE',
336
            build.title)
8322.9.2 by Celso Providelo
fixing test failures.
337
        self.assertEqual(build.buildqueue_record.lastscore, 1755)
5871.1.1 by Celso Providelo
Create build record when accepting new sources using queue-tool.
338
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
339
    def testAcceptingBinaryDoesntGenerateEmail(self):
340
        """Check if accepting a binary package does not generate email."""
341
        queue_action = self.execute_command(
342
            'accept mozilla-firefox', no_mail=False)
343
        self.assertEqual(1, queue_action.items_size)
344
        self.assertEqual(0, len(stub.test_emails))
345
5434.1.1 by Julian Edwards
Add/fix tests.
346
    def testAcceptingSourceClosesBug(self):
347
        """Check that accepting a source will close bugs appropriately."""
348
        # To speed up the publication process, single source uploads
349
        # are automatically published when they are accepted to avoid
350
        # another publisher cycle's worth of delay.  When the source is
351
        # published, any bugs mentioned in the upload must be closed.
352
353
        # First we must upload the first version of 'bar' in Ubuntu Hoary.
5508.1.1 by Julian Edwards
When accepting single source uploads that are unknown (ie. new packages),
354
        bar_src = self.uploadPackage()
5434.1.1 by Julian Edwards
Add/fix tests.
355
        bar_src.queue_root.setAccepted()
356
        bar_src.queue_root.realiseUpload()
357
358
        # Now make a new bugtask for the "bar" package.
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
359
        LaunchpadZopelessLayer.txn.commit()
360
        LaunchpadZopelessLayer.switchDbUser("launchpad")
361
5434.1.1 by Julian Edwards
Add/fix tests.
362
        the_bug_id = 6
363
        bugtask_owner = getUtility(IPersonSet).getByName('kinnison')
364
        ubuntu = getUtility(IDistributionSet)['ubuntu']
365
        ubuntu_bar = ubuntu.getSourcePackage('bar')
366
        the_bug = getUtility(IBugSet).get(the_bug_id)
367
        bugtask = getUtility(IBugTaskSet).createTask(
13571.2.2 by William Grant
BugTaskSet.createTask now takes an IBugTarget, not a key. Blergh.
368
            the_bug, bugtask_owner, ubuntu_bar)
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
369
5434.1.1 by Julian Edwards
Add/fix tests.
370
        LaunchpadZopelessLayer.txn.commit()
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
371
        LaunchpadZopelessLayer.switchDbUser(self.dbuser)
5434.1.1 by Julian Edwards
Add/fix tests.
372
373
        # The bugtask starts life as NEW.
374
        the_bug = getUtility(IBugSet).get(the_bug_id)
375
        bugtask = the_bug.getBugTask(ubuntu_bar)
376
        bug_status = bugtask.status.name
377
        self.assertEqual(
378
            bug_status, 'NEW',
379
            'Bug status is %s, expected NEW' % bug_status)
380
381
        # Now, make an upload for the next version of "bar".
5508.1.1 by Julian Edwards
When accepting single source uploads that are unknown (ie. new packages),
382
        bar2_src = self.uploadPackage(
383
            changesfile="suite/bar_1.0-2/bar_1.0-2_source.changes")
5434.1.1 by Julian Edwards
Add/fix tests.
384
385
        # Now accept the new bar upload with the queue tool.
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
386
        self.execute_command('accept bar', no_mail=False)
5434.1.1 by Julian Edwards
Add/fix tests.
387
388
        # The upload wants to close bug 6:
7675.787.15 by Jelmer Vernooij
When parsing DSC control files, use case insensitive lookups
389
        bugs_fixed_header = bar2_src.changes._dict['Launchpad-bugs-fixed']
5434.1.1 by Julian Edwards
Add/fix tests.
390
        self.assertEqual(
5434.1.2 by Julian Edwards
Apply bac's review comments and fix lint.
391
            bugs_fixed_header, str(the_bug_id),
7675.787.15 by Jelmer Vernooij
When parsing DSC control files, use case insensitive lookups
392
            'Expected bug %s in Launchpad-bugs-fixed, got %s'
5434.1.2 by Julian Edwards
Apply bac's review comments and fix lint.
393
                % (the_bug_id, bugs_fixed_header))
5434.1.1 by Julian Edwards
Add/fix tests.
394
395
        # The upload should be in the DONE state:
396
        item_status = bar2_src.queue_root.status.name
397
        self.assertEqual(
398
            item_status, 'DONE',
399
            'Upload status is %s, expected DONE' % item_status)
400
401
        # The bug should now be marked as fix released for the "bar"
402
        # bugtask:
403
        the_bug = getUtility(IBugSet).get(the_bug_id)
404
        bugtask = the_bug.getBugTask(ubuntu_bar)
405
        bug_status = bugtask.status.name
406
        self.assertEqual(
407
            bug_status, 'FIXRELEASED',
408
            'Bug status is %s, expected FIXRELEASED')
409
13747.1.2 by Steve Kowalik
Clean up bar_1.0-2 orig tarball madness.
410
        # Clean up.
411
        upload_data = datadir('suite/bar_1.0-2')
412
        os.remove(os.path.join(upload_data, 'bar_1.0.orig.tar.gz'))
413
4500.1.4 by Julian Edwards
First batch of tests added.
414
    def testAcceptActionWithMultipleIDs(self):
415
        """Check if accepting multiple items at once works.
416
417
        We can specify multiple items to accept, even mixing IDs and names.
418
        e.g. queue accept alsa-utils 1 3
419
        """
420
        breezy_autotest = getUtility(
421
            IDistributionSet)['ubuntu']['breezy-autotest']
422
        queue_action = self.execute_command('accept 1 pmount 3')
5821.10.20 by Celso Providelo
fixing queue-tool tests.
423
4500.1.4 by Julian Edwards
First batch of tests added.
424
        self.assertEqual(3, queue_action.items_size)
5821.10.20 by Celso Providelo
fixing queue-tool tests.
425
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
426
        self.assertQueueLength(1, breezy_autotest,
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
427
            PackageUploadStatus.ACCEPTED, u'mozilla-firefox')
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
428
        self.assertQueueLength(1, breezy_autotest,
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
429
            PackageUploadStatus.ACCEPTED, u'pmount')
5821.10.20 by Celso Providelo
fixing queue-tool tests.
430
        # Single-source upload went straight to DONE queue.
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
431
        self.assertQueueLength(1, breezy_autotest,
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
432
            PackageUploadStatus.DONE, u'netapplet')
4500.1.4 by Julian Edwards
First batch of tests added.
433
3147.5.48 by Celso Providelo
post-commit review comments, r=spiv
434
    def testRemovedPublishRecordDoesNotAffectQueueNewness(self):
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
435
        """Check if REMOVED published record does not affect file NEWness.
436
437
        We only mark a file as *known* if there is a PUBLISHED record with
438
        the same name, other states like SUPERSEDED or REMOVED doesn't count.
439
440
        This is the case of 'pmount_0.1-1' in ubuntu/breezy-autotest/i386,
441
        there is a REMOVED publishing record for it as you can see in the
442
        first part of the test.
443
444
        Following we can see the correct presentation of the new flag ('N').
3500.3.41 by Celso Providelo
review comments, r=spiv
445
        Bug #59291
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
446
        """
447
        # inspect publishing history in sampledata for the suspicious binary
448
        # ensure is has a single entry and it is merked as REMOVED.
449
        ubuntu = getUtility(IDistributionSet)['ubuntu']
450
        bat_i386 = ubuntu['breezy-autotest']['i386']
451
        moz_publishing = bat_i386.getBinaryPackage('pmount').releases
452
453
        self.assertEqual(1, len(moz_publishing))
4687.6.13 by Celso Providelo
fixing more test failures.
454
        self.assertEqual(PackagePublishingStatus.DELETED,
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
455
                         moz_publishing[0].status)
456
457
        # invoke queue tool filtering by name
3500.3.41 by Celso Providelo
review comments, r=spiv
458
        queue_action = self.execute_command('info pmount')
459
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
460
        # ensure we retrived a single item
3500.3.41 by Celso Providelo
review comments, r=spiv
461
        self.assertEqual(1, queue_action.items_size)
462
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
463
        # and it is what we expect
3500.3.41 by Celso Providelo
review comments, r=spiv
464
        self.assertEqual('pmount', queue_action.items[0].displayname)
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
465
        self.assertEqual(moz_publishing[0].binarypackagerelease.build,
3500.3.41 by Celso Providelo
review comments, r=spiv
466
                         queue_action.items[0].builds[0].build)
467
        # inspect output, note the presence of 'N' flag
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
468
        self.assertTrue(
3500.3.41 by Celso Providelo
review comments, r=spiv
469
            '| N pmount/0.1-1/i386' in '\n'.join(self.test_output))
470
471
    def testQueueSupportForSuiteNames(self):
3500.3.39 by Celso Providelo
Fix bug #59280 (add suite support in queue tool)
472
        """Queue tool supports suite names properly.
473
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
474
        Two UNAPPROVED items are present for pocket RELEASE and only
3500.3.39 by Celso Providelo
Fix bug #59280 (add suite support in queue tool)
475
        one for pocket UPDATES in breezy-autotest.
3500.3.41 by Celso Providelo
review comments, r=spiv
476
        Bug #59280
3500.3.39 by Celso Providelo
Fix bug #59280 (add suite support in queue tool)
477
        """
3500.3.41 by Celso Providelo
review comments, r=spiv
478
        queue_action = self.execute_command(
479
            'info', queue_name='unapproved',
480
            suite_name='breezy-autotest')
481
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
482
        self.assertEqual(2, queue_action.items_size)
3500.3.41 by Celso Providelo
review comments, r=spiv
483
        self.assertEqual(PackagePublishingPocket.RELEASE, queue_action.pocket)
484
485
        queue_action = self.execute_command(
486
            'info', queue_name='unapproved',
487
            suite_name='breezy-autotest-updates')
488
489
        self.assertEqual(1, queue_action.items_size)
490
        self.assertEqual(PackagePublishingPocket.UPDATES, queue_action.pocket)
3500.3.39 by Celso Providelo
Fix bug #59280 (add suite support in queue tool)
491
3686.1.36 by Celso Providelo
partially fix bug #59443 (do not announce BACKPORTS acceptance), hijack some changes from queue-ui to fill/remove sampledata librarian file contents on-the-fly, they will conflict at some point.
492
    def testQueueDoesNotAnnounceBackports(self):
493
        """Check if BACKPORTS acceptance are not announced publicly.
494
495
        Queue tool normally announce acceptance in the specified changeslist
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
496
        for the distroseries in question, however BACKPORTS announce doesn't
3686.1.36 by Celso Providelo
partially fix bug #59443 (do not announce BACKPORTS acceptance), hijack some changes from queue-ui to fill/remove sampledata librarian file contents on-the-fly, they will conflict at some point.
497
        fit very well in that list, they cause unwanted noise.
498
499
        Further details in bug #59443
500
        """
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
501
        LaunchpadZopelessLayer.switchDbUser("launchpad")
5821.10.20 by Celso Providelo
fixing queue-tool tests.
502
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
503
        # Make breezy-autotest CURRENT in order to accept upload
504
        # to BACKPORTS.
3686.1.36 by Celso Providelo
partially fix bug #59443 (do not announce BACKPORTS acceptance), hijack some changes from queue-ui to fill/remove sampledata librarian file contents on-the-fly, they will conflict at some point.
505
        breezy_autotest = getUtility(
506
            IDistributionSet)['ubuntu']['breezy-autotest']
10054.26.1 by Adi Roiban
Refactor DistroSeriesStatus to SeriesStatus; Don't prompt for setting up translations for obsolete product series.
507
        breezy_autotest.status = SeriesStatus.CURRENT
3686.1.36 by Celso Providelo
partially fix bug #59443 (do not announce BACKPORTS acceptance), hijack some changes from queue-ui to fill/remove sampledata librarian file contents on-the-fly, they will conflict at some point.
508
5821.10.20 by Celso Providelo
fixing queue-tool tests.
509
        LaunchpadZopelessLayer.txn.commit()
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
510
        LaunchpadZopelessLayer.switchDbUser(self.dbuser)
5821.10.20 by Celso Providelo
fixing queue-tool tests.
511
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
512
        # Store the targeted queue item for future inspection.
513
        # Ensure it is what we expect.
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
514
        target_queue = breezy_autotest.getPackageUploads(
3691.443.57 by Celso Providelo
fixing more test failures.
515
            status=PackageUploadStatus.UNAPPROVED,
13211.1.1 by Jeroen Vermeulen
Lint.
516
            pocket=PackagePublishingPocket.BACKPORTS)[0]
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
517
        self.assertEqual(10, target_queue.id)
518
519
        # Ensure breezy-autotest is set.
3686.1.36 by Celso Providelo
partially fix bug #59443 (do not announce BACKPORTS acceptance), hijack some changes from queue-ui to fill/remove sampledata librarian file contents on-the-fly, they will conflict at some point.
520
        self.assertEqual(
3686.1.39 by Celso Providelo
typo in sampledata and obsolete test function removed.
521
            u'autotest_changes@ubuntu.com', breezy_autotest.changeslist)
3686.1.36 by Celso Providelo
partially fix bug #59443 (do not announce BACKPORTS acceptance), hijack some changes from queue-ui to fill/remove sampledata librarian file contents on-the-fly, they will conflict at some point.
522
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
523
        # Accept the sampledata item.
3686.1.36 by Celso Providelo
partially fix bug #59443 (do not announce BACKPORTS acceptance), hijack some changes from queue-ui to fill/remove sampledata librarian file contents on-the-fly, they will conflict at some point.
524
        queue_action = self.execute_command(
525
            'accept', queue_name='unapproved',
526
            suite_name='breezy-autotest-backports', no_mail=False)
527
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
528
        # Only one item considered.
3686.1.36 by Celso Providelo
partially fix bug #59443 (do not announce BACKPORTS acceptance), hijack some changes from queue-ui to fill/remove sampledata librarian file contents on-the-fly, they will conflict at some point.
529
        self.assertEqual(1, queue_action.items_size)
530
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
531
        # Previously stored reference should have new state now
532
        self.assertEqual('ACCEPTED', target_queue.status.name)
533
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
534
        # Only one email is sent to the changed-by email on the changes
535
        # file.  No announcement email is sent.
536
        self.assertEqual(len(stub.test_emails), 1)
537
        self.assertEmail(
538
            ['Daniel Silverstone <daniel.silverstone@canonical.com>'])
3686.1.36 by Celso Providelo
partially fix bug #59443 (do not announce BACKPORTS acceptance), hijack some changes from queue-ui to fill/remove sampledata librarian file contents on-the-fly, they will conflict at some point.
539
3811.3.5 by Celso Providelo
applying review comments [r=salgado]
540
    def testQueueDoesNotSendAnyEmailsForTranslations(self):
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
541
        """Check if no emails are sent when accepting translations.
542
543
        Queue tool should not send any emails to source uploads targeted to
544
        'translation' section.
545
        They are the 'language-pack-*' and 'language-support-*' sources.
546
547
        Further details in bug #57708
548
        """
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
549
        LaunchpadZopelessLayer.switchDbUser("launchpad")
5821.10.20 by Celso Providelo
fixing queue-tool tests.
550
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
551
        # Make breezy-autotest CURRENT in order to accept upload
552
        # to PROPOSED.
553
        breezy_autotest = getUtility(
554
            IDistributionSet)['ubuntu']['breezy-autotest']
10054.26.1 by Adi Roiban
Refactor DistroSeriesStatus to SeriesStatus; Don't prompt for setting up translations for obsolete product series.
555
        breezy_autotest.status = SeriesStatus.CURRENT
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
556
5821.10.20 by Celso Providelo
fixing queue-tool tests.
557
        LaunchpadZopelessLayer.txn.commit()
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
558
        LaunchpadZopelessLayer.switchDbUser(self.dbuser)
5821.10.20 by Celso Providelo
fixing queue-tool tests.
559
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
560
        # Store the targeted queue item for future inspection.
561
        # Ensure it is what we expect.
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
562
        target_queue = breezy_autotest.getPackageUploads(
3691.443.57 by Celso Providelo
fixing more test failures.
563
            status=PackageUploadStatus.UNAPPROVED,
564
            pocket=PackagePublishingPocket.PROPOSED)[0]
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
565
        self.assertEqual(12, target_queue.id)
566
        source = target_queue.sources[0].sourcepackagerelease
567
        self.assertEqual('translations', source.section.name)
568
569
        # Accept the sampledata item.
570
        queue_action = self.execute_command(
571
            'accept', queue_name='unapproved',
572
            suite_name='breezy-autotest-proposed', no_mail=False)
573
574
        # Only one item considered.
575
        self.assertEqual(1, queue_action.items_size)
576
5434.1.1 by Julian Edwards
Add/fix tests.
577
        # Previously stored reference should have new state now.
578
        self.assertEqual('DONE', target_queue.status.name)
3811.3.3 by Celso Providelo
Fix #57708 (do not generate emails for language-pack uploads) at queue time [2/2]
579
580
        # No email was sent.
581
        self.assertEqual(0, len(stub.test_emails))
582
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
583
    def assertQueueLength(self, expected_length, distro_series, status, name):
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
584
        queue_items = distro_series.getPackageUploads(
585
            status=status, name=name)
5821.10.20 by Celso Providelo
fixing queue-tool tests.
586
        self.assertEqual(expected_length, queue_items.count())
3500.3.46 by Celso Providelo
review comments, r=spiv
587
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
588
    def assertErrorAcceptingDuplicate(self):
589
        self.assertTrue(
5434.1.1 by Julian Edwards
Add/fix tests.
590
            '** cnews could not be accepted due to '
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
591
            'The source cnews - 1.0 is already accepted in ubuntu/'
592
            'breezy-autotest and you cannot upload the same version '
593
            'within the same distribution. You have to modify the source '
594
            'version and re-upload.' in self.test_output)
595
3500.3.46 by Celso Providelo
review comments, r=spiv
596
    def testAcceptanceWorkflowForDuplications(self):
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
597
        """Check how queue tool behaves dealing with duplicated entries.
598
599
        Sampledata provides a duplication of cnews_1.0 in breezy-autotest
600
        UNAPPROVED queue.
601
3500.3.48 by Celso Providelo
split workarround task from bug #62976 into bug #65052, so this branch is supposed to implement only the workaround required to fix the last, the former still oppened. Also some review comments applyed, r=spiv
602
        Step 1:  executing 'accept cnews in unapproved queue' with duplicate
603
        cnews items in the UNAPPROVED queue, results in the oldest being
604
        accepted and the newer one remaining UNAPPROVED (and displaying
605
        an error about it to the user).
606
607
        Step 2: executing 'accept cnews in unapproved queue' with duplicate
608
        cnews items in the UNAPPROVED and ACCEPTED queues has no effect on
609
        the queues, and again displays an error to the user.
610
611
        Step 3: executing 'accept cnews in unapproved queue' with duplicate
612
        cnews items in the UNAPPROVED and DONE queues behaves the same as 2.
613
614
        Step 4: the remaining duplicated cnews item in UNAPPROVED queue can
615
        only be rejected.
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
616
        """
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
617
        LaunchpadZopelessLayer.switchDbUser("launchpad")
6200.2.13 by Celso Providelo
Fixing test failures.
618
619
        # Add a chroot to breezy-autotest/i386, so the system can create
620
        # builds for it.
621
        a_file = getUtility(ILibraryFileAliasSet)[1]
3500.3.46 by Celso Providelo
review comments, r=spiv
622
        breezy_autotest = getUtility(
623
            IDistributionSet)['ubuntu']['breezy-autotest']
6200.2.13 by Celso Providelo
Fixing test failures.
624
        breezy_autotest['i386'].addOrUpdateChroot(a_file)
625
626
        LaunchpadZopelessLayer.txn.commit()
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
627
        LaunchpadZopelessLayer.switchDbUser(self.dbuser)
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
628
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
629
        # Certify we have a 'cnews' upload duplication in UNAPPROVED.
3500.3.46 by Celso Providelo
review comments, r=spiv
630
        self.assertQueueLength(
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
631
            2, breezy_autotest, PackageUploadStatus.UNAPPROVED, u"cnews")
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
632
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
633
        # Step 1: try to accept both.
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
634
        self.execute_command(
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
635
            'accept cnews', queue_name='unapproved',
636
            suite_name='breezy-autotest')
637
5821.10.20 by Celso Providelo
fixing queue-tool tests.
638
        # The first item, being a single source upload, is automatically
639
        # published when it's accepted.
3500.3.46 by Celso Providelo
review comments, r=spiv
640
        self.assertQueueLength(
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
641
            1, breezy_autotest, PackageUploadStatus.DONE, u"cnews")
3500.3.46 by Celso Providelo
review comments, r=spiv
642
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
643
        # The last can't be accepted and remains in UNAPPROVED.
644
        self.assertErrorAcceptingDuplicate()
3500.3.46 by Celso Providelo
review comments, r=spiv
645
        self.assertQueueLength(
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
646
            1, breezy_autotest, PackageUploadStatus.UNAPPROVED, u"cnews")
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
647
3500.3.48 by Celso Providelo
split workarround task from bug #62976 into bug #65052, so this branch is supposed to implement only the workaround required to fix the last, the former still oppened. Also some review comments applyed, r=spiv
648
        # Step 2: try to accept the remaining item in UNAPPROVED.
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
649
        self.execute_command(
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
650
            'accept cnews', queue_name='unapproved',
651
            suite_name='breezy-autotest')
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
652
        self.assertErrorAcceptingDuplicate()
3500.3.46 by Celso Providelo
review comments, r=spiv
653
        self.assertQueueLength(
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
654
            1, breezy_autotest, PackageUploadStatus.UNAPPROVED, u"cnews")
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
655
3500.3.48 by Celso Providelo
split workarround task from bug #62976 into bug #65052, so this branch is supposed to implement only the workaround required to fix the last, the former still oppened. Also some review comments applyed, r=spiv
656
        # Step 3: try to accept the remaining item in UNAPPROVED with the
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
657
        # duplication already in DONE.
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
658
        self.execute_command(
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
659
            'accept cnews', queue_name='unapproved',
660
            suite_name='breezy-autotest')
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
661
        # It failed and te item remains in UNAPPROVED.
662
        self.assertErrorAcceptingDuplicate()
3500.3.46 by Celso Providelo
review comments, r=spiv
663
        self.assertQueueLength(
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
664
            1, breezy_autotest, PackageUploadStatus.UNAPPROVED, u"cnews")
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
665
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
666
        # Step 4: The only possible destiny for the remaining item it REJECT.
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
667
        self.execute_command(
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
668
            'reject cnews', queue_name='unapproved',
669
            suite_name='breezy-autotest')
3500.3.46 by Celso Providelo
review comments, r=spiv
670
        self.assertQueueLength(
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
671
            0, breezy_autotest, PackageUploadStatus.UNAPPROVED, u"cnews")
3500.3.46 by Celso Providelo
review comments, r=spiv
672
        self.assertQueueLength(
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
673
            1, breezy_autotest, PackageUploadStatus.REJECTED, u"cnews")
3500.3.46 by Celso Providelo
review comments, r=spiv
674
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
675
    def testRejectSourceSendsEmail(self):
676
        """Check that rejecting a source upload sends email."""
677
        queue_action = self.execute_command(
678
            'reject alsa-utils', no_mail=False)
679
        self.assertEqual(1, queue_action.items_size)
680
        self.assertEqual(1, len(stub.test_emails))
681
        self.assertEmail(
682
            ['Daniel Silverstone <daniel.silverstone@canonical.com>'])
683
684
    def testRejectBinarySendsEmail(self):
685
        """Check that rejecting a binary upload sends email."""
686
        queue_action = self.execute_command('reject 2', no_mail=False)
687
        self.assertEqual(1, queue_action.items_size)
688
        self.assertEqual(1, len(stub.test_emails))
689
        self.assertEmail(
690
            ['Daniel Silverstone <daniel.silverstone@canonical.com>'])
691
5590.1.1 by Julian Edwards
Don't send email notifications for any language packs (fixes bug 187285)
692
    def testRejectLangpackSendsNoEmail(self):
693
        """Check that rejecting a language pack sends no email."""
694
        queue_action = self.execute_command(
695
            'reject language-pack-de', queue_name='unapproved',
696
            suite_name='breezy-autotest-proposed')
697
        self.assertEqual(1, queue_action.items_size)
698
        self.assertEqual(0, len(stub.test_emails))
699
4500.1.7 by Julian Edwards
Add more tests.
700
    def testRejectWithMultipleIDs(self):
701
        """Check if rejecting multiple items at once works.
702
703
        We can specify multiple items to reject, even mixing IDs and names.
704
        e.g. queue reject alsa-utils 1 3
705
        """
706
        breezy_autotest = getUtility(
707
            IDistributionSet)['ubuntu']['breezy-autotest']
708
709
        # Run the command.
710
        queue_action = self.execute_command('reject 1 pmount 3')
711
712
        # Test what it did.  Since all the queue items came out of the
713
        # NEW queue originally, the items processed should now be REJECTED.
714
        self.assertEqual(3, queue_action.items_size)
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
715
        self.assertQueueLength(1, breezy_autotest,
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
716
            PackageUploadStatus.REJECTED, u'mozilla-firefox')
717
        self.assertQueueLength(1, breezy_autotest,
718
            PackageUploadStatus.REJECTED, u'pmount')
719
        self.assertQueueLength(1, breezy_autotest,
720
            PackageUploadStatus.REJECTED, u'netapplet')
4500.1.7 by Julian Edwards
Add more tests.
721
722
    def testOverrideSource(self):
723
        """Check if overriding sources works.
724
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
725
        We can specify multiple items to override, even mixing IDs and names.
4500.1.7 by Julian Edwards
Add more tests.
726
        e.g. queue override source -c restricted alsa-utils 1 3
727
        """
728
        # Set up.
729
        breezy_autotest = getUtility(
730
            IDistributionSet)['ubuntu']['breezy-autotest']
731
732
        # Basic operation overriding a single source 'alsa-utils' that
733
        # is currently main/base in the sample data.
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
734
        queue_action = self.execute_command('override source 4',
4500.1.7 by Julian Edwards
Add more tests.
735
            component_name='restricted', section_name='web')
736
        self.assertEqual(1, queue_action.items_size)
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
737
        queue_item = breezy_autotest.getPackageUploads(
738
            status=PackageUploadStatus.NEW, name=u"alsa-utils")[0]
4500.1.7 by Julian Edwards
Add more tests.
739
        [source] = queue_item.sources
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
740
        self.assertEqual('restricted',
4500.1.7 by Julian Edwards
Add more tests.
741
            source.sourcepackagerelease.component.name)
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
742
        self.assertEqual('web',
4500.1.7 by Julian Edwards
Add more tests.
743
            source.sourcepackagerelease.section.name)
744
745
        # Override multiple sources at once and mix ID with name.
746
        queue_action = self.execute_command('override source 4 netapplet',
747
            component_name='universe', section_name='editors')
748
        # 'netapplet' appears 3 times, alsa-utils once.
749
        self.assertEqual(4, queue_action.items_size)
11277.2.1 by William Grant
Only override each PackageUpload's packages once, even if it matches multiple names given on the command line. Add tests to ensure that sources and binaries are overridden only once each.
750
        self.assertEqual(2, queue_action.overrides_performed)
4500.1.7 by Julian Edwards
Add more tests.
751
        # Check results.
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
752
        queue_items = list(breezy_autotest.getPackageUploads(
753
            status=PackageUploadStatus.NEW, name=u'alsa-utils'))
754
        queue_items.extend(list(breezy_autotest.getPackageUploads(
755
            status=PackageUploadStatus.NEW, name=u'netapplet')))
4500.1.7 by Julian Edwards
Add more tests.
756
        for queue_item in queue_items:
757
            if queue_item.sources:
758
                [source] = queue_item.sources
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
759
                self.assertEqual('universe',
4500.1.7 by Julian Edwards
Add more tests.
760
                    source.sourcepackagerelease.component.name)
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
761
                self.assertEqual('editors',
4500.1.7 by Julian Edwards
Add more tests.
762
                    source.sourcepackagerelease.section.name)
763
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
764
    def testOverrideSourceWithArchiveChange(self):
765
        """Check if the archive changes as necessary on a source override.
766
767
        When overriding the component, the archive may change, so we check
768
        that here.
769
        """
770
        # Set up.
4376.2.52 by Julian Edwards
Pre-publication overrides of source packages should abort if the override
771
        ubuntu = getUtility(IDistributionSet)['ubuntu']
772
        breezy_autotest = ubuntu['breezy-autotest']
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
773
4810.9.1 by Julian Edwards
All occurrences of commercial, Commercial or COMMERCIAL are now partner,
774
        # Test that it changes to partner when required.
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
775
        queue_action = self.execute_command('override source alsa-utils',
4810.9.1 by Julian Edwards
All occurrences of commercial, Commercial or COMMERCIAL are now partner,
776
            component_name='partner')
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
777
        self.assertEqual(1, queue_action.items_size)
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
778
        [queue_item] = breezy_autotest.getPackageUploads(
779
            status=PackageUploadStatus.NEW, name=u"alsa-utils")
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
780
        [source] = queue_item.sources
781
        self.assertEqual(source.sourcepackagerelease.upload_archive.purpose,
4810.9.1 by Julian Edwards
All occurrences of commercial, Commercial or COMMERCIAL are now partner,
782
            ArchivePurpose.PARTNER)
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
783
784
        # Test that it changes back to primary when required.
785
        queue_action = self.execute_command('override source alsa-utils',
786
            component_name='main')
787
        self.assertEqual(1, queue_action.items_size)
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
788
        [queue_item] = breezy_autotest.getPackageUploads(
789
            status=PackageUploadStatus.NEW, name=u"alsa-utils")
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
790
        [source] = queue_item.sources
791
        self.assertEqual(source.sourcepackagerelease.upload_archive.purpose,
792
            ArchivePurpose.PRIMARY)
793
4376.2.73 by Julian Edwards
Apply review comments.
794
    def testOverrideSourceWithNonexistentArchiveChange(self):
795
        """Check that overriding to a non-existent archive fails properly.
796
797
        When overriding the component, the archive may change to a
798
        non-existent one so ensure if fails.
799
        """
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
800
        LaunchpadZopelessLayer.switchDbUser("launchpad")
801
4376.2.73 by Julian Edwards
Apply review comments.
802
        ubuntu = getUtility(IDistributionSet)['ubuntu']
4376.2.52 by Julian Edwards
Pre-publication overrides of source packages should abort if the override
803
        proxied_archive = getUtility(IArchiveSet).getByDistroPurpose(
4810.9.1 by Julian Edwards
All occurrences of commercial, Commercial or COMMERCIAL are now partner,
804
            ubuntu, ArchivePurpose.PARTNER)
4376.2.52 by Julian Edwards
Pre-publication overrides of source packages should abort if the override
805
        comm_archive = removeSecurityProxy(proxied_archive)
6374.15.13 by Barry Warsaw
mergeRF
806
        comm_archive.purpose = ArchivePurpose.PPA
4376.2.52 by Julian Edwards
Pre-publication overrides of source packages should abort if the override
807
        LaunchpadZopelessLayer.txn.commit()
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
808
        LaunchpadZopelessLayer.switchDbUser(self.dbuser)
809
4376.2.52 by Julian Edwards
Pre-publication overrides of source packages should abort if the override
810
        self.assertRaises(CommandRunnerError,
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
811
                          self.execute_command,
4376.2.52 by Julian Edwards
Pre-publication overrides of source packages should abort if the override
812
                          'override source alsa-utils',
4810.9.1 by Julian Edwards
All occurrences of commercial, Commercial or COMMERCIAL are now partner,
813
                          component_name='partner')
4376.2.52 by Julian Edwards
Pre-publication overrides of source packages should abort if the override
814
4500.1.7 by Julian Edwards
Add more tests.
815
    def testOverrideBinary(self):
816
        """Check if overriding binaries works.
817
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
818
        We can specify multiple items to override, even mixing IDs and names.
4500.1.7 by Julian Edwards
Add more tests.
819
        e.g. queue override binary -c restricted alsa-utils 1 3
820
        """
821
        # Set up.
822
        breezy_autotest = getUtility(
823
            IDistributionSet)['ubuntu']['breezy-autotest']
824
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
825
        # Override a binary, 'pmount', from its sample data of
4500.1.7 by Julian Edwards
Add more tests.
826
        # main/base/IMPORTANT to restricted/web/extra.
827
        queue_action = self.execute_command('override binary pmount',
828
            component_name='restricted', section_name='web',
829
            priority_name='extra')
830
        self.assertEqual(1, queue_action.items_size)
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
831
        [queue_item] = breezy_autotest.getPackageUploads(
832
            status=PackageUploadStatus.NEW, name=u"pmount")
4500.1.7 by Julian Edwards
Add more tests.
833
        [packagebuild] = queue_item.builds
834
        for package in packagebuild.build.binarypackages:
835
            self.assertEqual('restricted', package.component.name)
836
            self.assertEqual('web', package.section.name)
837
            self.assertEqual('EXTRA', package.priority.name)
838
839
        # Override multiple binaries at once.
840
        queue_action = self.execute_command(
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
841
            'override binary pmount mozilla-firefox',
4500.1.7 by Julian Edwards
Add more tests.
842
            component_name='universe', section_name='editors',
843
            priority_name='optional')
844
        # Check results.
845
        self.assertEqual(2, queue_action.items_size)
11277.2.1 by William Grant
Only override each PackageUpload's packages once, even if it matches multiple names given on the command line. Add tests to ensure that sources and binaries are overridden only once each.
846
        self.assertEqual(2, queue_action.overrides_performed)
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
847
        queue_items = list(breezy_autotest.getPackageUploads(
848
            status=PackageUploadStatus.NEW, name=u'pmount'))
849
        queue_items.extend(list(breezy_autotest.getPackageUploads(
850
            status=PackageUploadStatus.NEW, name=u'mozilla-firefox')))
4500.1.7 by Julian Edwards
Add more tests.
851
        for queue_item in queue_items:
852
            [packagebuild] = queue_item.builds
853
            for package in packagebuild.build.binarypackages:
854
                self.assertEqual('universe', package.component.name)
855
                self.assertEqual('editors', package.section.name)
856
                self.assertEqual('OPTIONAL', package.priority.name)
857
858
        # Check that overriding by ID is warned to the user.
859
        self.assertRaises(
860
            CommandRunnerError, self.execute_command, 'override binary 1',
861
            component_name='multiverse')
862
4989.2.1 by Julian Edwards
Overriding multiple binaries from the same build now works.
863
    def testOverridingMulipleBinariesFromSameBuild(self):
864
        """Check that multiple binary override works for the same build.
865
866
        Overriding binary packages generated from the same build should
867
        override each package individually.
868
        """
869
        # Start off by setting up a packageuploadbuild that points to
4989.2.3 by Julian Edwards
Apply flacoste's mentor review comments.
870
        # a build with two binaries.
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
871
        LaunchpadZopelessLayer.switchDbUser("launchpad")
872
4989.2.1 by Julian Edwards
Overriding multiple binaries from the same build now works.
873
        breezy_autotest = getUtility(
874
            IDistributionSet)['ubuntu']['breezy-autotest']
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
875
        [mozilla_queue_item] = breezy_autotest.getPackageUploads(
876
            status=PackageUploadStatus.NEW, name=u'mozilla-firefox')
4989.2.3 by Julian Edwards
Apply flacoste's mentor review comments.
877
4989.2.1 by Julian Edwards
Overriding multiple binaries from the same build now works.
878
        # The build with ID '2' is for mozilla-firefox, which produces
879
        # binaries for 'mozilla-firefox' and 'mozilla-firefox-data'.
880
        PackageUploadBuild(packageupload=mozilla_queue_item, build=2)
4989.2.3 by Julian Edwards
Apply flacoste's mentor review comments.
881
882
        # Switching db users starts a new transaction.  We must re-fetch
883
        # breezy-autotest.
5821.6.32 by Celso Providelo
removing usages of 'testadmin' user.
884
        LaunchpadZopelessLayer.txn.commit()
4989.2.3 by Julian Edwards
Apply flacoste's mentor review comments.
885
        LaunchpadZopelessLayer.switchDbUser("queued")
886
        breezy_autotest = getUtility(
887
            IDistributionSet)['ubuntu']['breezy-autotest']
4989.2.1 by Julian Edwards
Overriding multiple binaries from the same build now works.
888
889
        queue_action = self.execute_command(
890
            'override binary mozilla-firefox-data mozilla-firefox',
891
            component_name='restricted', section_name='editors',
892
            priority_name='optional')
893
11277.2.1 by William Grant
Only override each PackageUpload's packages once, even if it matches multiple names given on the command line. Add tests to ensure that sources and binaries are overridden only once each.
894
        # There are three binaries to override on this PackageUpload:
895
        #  - mozilla-firefox in breezy-autotest
896
        #  - mozilla-firefox and mozilla-firefox-data in warty
897
        # Each should be overridden exactly once.
898
        self.assertEqual(1, queue_action.items_size)
899
        self.assertEqual(3, queue_action.overrides_performed)
900
13233.2.6 by Jeroen Vermeulen
Kill getQueueItems.
901
        queue_items = list(breezy_autotest.getPackageUploads(
902
            status=PackageUploadStatus.NEW, name=u'mozilla-firefox-data'))
903
        queue_items.extend(list(breezy_autotest.getPackageUploads(
904
            status=PackageUploadStatus.NEW, name=u'mozilla-firefox')))
4989.2.1 by Julian Edwards
Overriding multiple binaries from the same build now works.
905
        for queue_item in queue_items:
906
            for packagebuild in queue_item.builds:
907
                for package in packagebuild.build.binarypackages:
4989.2.3 by Julian Edwards
Apply flacoste's mentor review comments.
908
                    self.assertEqual(
909
                        'restricted', package.component.name,
910
                        "The component '%s' is not the expected 'restricted'"
911
                        "for package %s" % (
912
                            package.component.name, package.name))
913
                    self.assertEqual(
914
                        'editors', package.section.name,
915
                        "The section '%s' is not the expected 'editors'"
916
                        "for package %s" % (
917
                            package.section.name, package.name))
918
                    self.assertEqual(
919
                        'OPTIONAL', package.priority.name,
920
                        "The priority '%s' is not the expected 'OPTIONAL'"
921
                        "for package %s" % (
922
                            package.section.name, package.name))
4989.2.1 by Julian Edwards
Overriding multiple binaries from the same build now works.
923
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
924
    def testOverrideBinaryWithArchiveChange(self):
4376.2.38 by Julian Edwards
Queue override binary is disallowed if the archive changes.
925
        """Check if archive changes are disallowed for binary overrides.
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
926
927
        When overriding the component, the archive may change, so we check
4376.2.38 by Julian Edwards
Queue override binary is disallowed if the archive changes.
928
        that here and make sure it's disallowed.
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
929
        """
4810.9.1 by Julian Edwards
All occurrences of commercial, Commercial or COMMERCIAL are now partner,
930
        # Test that it changes to partner when required.
4376.2.38 by Julian Edwards
Queue override binary is disallowed if the archive changes.
931
        self.assertRaises(
5152.4.20 by Celso Providelo
Fixing bug #172373 (clearer rejection message for duplicated uploads within the same distribution).
932
            CommandRunnerError, self.execute_command,
933
            'override binary pmount', component_name='partner')
4376.2.22 by Julian Edwards
Fix overrides in the queue tool so that component changes that change the
934
3500.3.46 by Celso Providelo
review comments, r=spiv
935
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
936
class TestQueueActionLite(TestCaseWithFactory):
937
    """A lightweight unit test case for `QueueAction`.
938
939
    Meant for detailed tests that would be too expensive for full end-to-end
940
    tests.
941
    """
942
943
    layer = LaunchpadZopelessLayer
944
13382.3.1 by Julian Edwards
Add a failing test to check setting overrides from the queue script.
945
    def makeQueueAction(self, package_upload, distroseries=None,
946
                        component=None, section=None,
947
                        action_type=QueueAction):
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
948
        """Create a `QueueAction` for use with a `PackageUpload`.
949
950
        The action's `display` method is set to a `FakeMethod`.
951
        """
952
        if distroseries is None:
13211.2.5 by Jeroen Vermeulen
Review changes.
953
            distroseries = self.factory.makeDistroSeries(
13382.3.1 by Julian Edwards
Add a failing test to check setting overrides from the queue script.
954
                status=SeriesStatus.CURRENT,
955
                name="distroseriestestingpcjs")
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
956
        distro = distroseries.distribution
957
        if package_upload is None:
958
            package_upload = self.factory.makePackageUpload(
959
                distroseries=distroseries, archive=distro.main_archive)
13382.3.1 by Julian Edwards
Add a failing test to check setting overrides from the queue script.
960
        if component is None:
961
            component = self.factory.makeComponent()
962
        if section is None:
963
            section = self.factory.makeSection()
964
        queue = PackageUploadStatus.NEW
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
965
        priority_name = "STANDARD"
966
        display = FakeMethod()
967
        terms = ['*']
13382.3.1 by Julian Edwards
Add a failing test to check setting overrides from the queue script.
968
        return action_type(
969
            distro.name, distroseries.name, queue, terms, component.name,
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
970
            section.name, priority_name, display)
971
13382.3.1 by Julian Edwards
Add a failing test to check setting overrides from the queue script.
972
    def makeQueueActionOverride(self, package_upload, component, section,
973
                                distroseries=None):
974
        return self.makeQueueAction(
975
            package_upload, distroseries, component, section,
976
            action_type=QueueActionOverride)
977
13277.2.2 by Jeroen Vermeulen
Fix the upload tag in the queue script for copy-job uploads.
978
    def parseUploadSummaryLine(self, output_line):
979
        """Parse an output line from `QueueAction.displayItem`.
980
981
        :param output_line: A line of output text from `displayItem`.
982
        :return: A tuple of displayed items: (id, tag, name, version, age).
983
        """
984
        return tuple(item.strip() for item in output_line.split('|'))
985
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
986
    def test_display_actions_have_privileges_for_PackageCopyJob(self):
987
        # The methods that display uploads have privileges to work with
988
        # a PackageUpload that has a copy job.
989
        # Bundling tests for multiple operations into one test because
990
        # the database user change requires a costly commit.
13211.2.5 by Jeroen Vermeulen
Review changes.
991
        upload = self.factory.makeCopyJobPackageUpload()
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
992
        action = self.makeQueueAction(upload)
993
        self.layer.txn.commit()
994
        self.layer.switchDbUser(config.uploadqueue.dbuser)
995
996
        action.displayItem(upload)
997
        self.assertNotEqual(0, action.display.call_count)
998
        action.display.calls = []
999
        action.displayInfo(upload)
1000
        self.assertNotEqual(0, action.display.call_count)
1001
1002
    def test_accept_actions_have_privileges_for_PackageCopyJob(self):
13211.2.5 by Jeroen Vermeulen
Review changes.
1003
        # The script also has privileges to approve uploads that have
1004
        # copy jobs.
1005
        distroseries = self.factory.makeDistroSeries(
1006
            status=SeriesStatus.CURRENT)
1007
        upload = self.factory.makeCopyJobPackageUpload(distroseries)
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
1008
        self.layer.txn.commit()
1009
        self.layer.switchDbUser(config.uploadqueue.dbuser)
1010
        upload.acceptFromQueue(DevNullLogger(), dry_run=True)
1011
        # Flush changes to make sure we're not caching any updates that
1012
        # the database won't allow.  If this passes, we've got the
1013
        # privileges.
1014
        IStore(upload).flush()
1015
1016
    def test_displayItem_displays_PackageUpload_with_source(self):
13211.2.5 by Jeroen Vermeulen
Review changes.
1017
        # displayItem can display a source package upload.
1018
        upload = self.factory.makeSourcePackageUpload()
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
1019
        action = self.makeQueueAction(upload)
13277.2.2 by Jeroen Vermeulen
Fix the upload tag in the queue script for copy-job uploads.
1020
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
1021
        action.displayItem(upload)
13277.2.2 by Jeroen Vermeulen
Fix the upload tag in the queue script for copy-job uploads.
1022
1023
        ((output, ), kwargs) = action.display.calls[0]
1024
        (upload_id, tag, name, version, age) = self.parseUploadSummaryLine(
1025
            output)
1026
        self.assertEqual(str(upload.id), upload_id)
1027
        self.assertEqual("S-", tag)
1028
        self.assertThat(upload.displayname, StartsWith(name))
1029
        self.assertThat(upload.package_version, StartsWith(version))
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
1030
1031
    def test_displayItem_displays_PackageUpload_with_PackageCopyJob(self):
13211.2.5 by Jeroen Vermeulen
Review changes.
1032
        # displayItem can display a copy-job package upload.
1033
        upload = self.factory.makeCopyJobPackageUpload()
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
1034
        action = self.makeQueueAction(upload)
13277.2.2 by Jeroen Vermeulen
Fix the upload tag in the queue script for copy-job uploads.
1035
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
1036
        action.displayItem(upload)
13277.2.2 by Jeroen Vermeulen
Fix the upload tag in the queue script for copy-job uploads.
1037
1038
        ((output, ), kwargs) = action.display.calls[0]
1039
        (upload_id, tag, name, version, age) = self.parseUploadSummaryLine(
1040
            output)
1041
        self.assertEqual(str(upload.id), upload_id)
1042
        self.assertEqual("X-", tag)
1043
        self.assertThat(upload.displayname, StartsWith(name))
1044
        self.assertThat(upload.package_version, StartsWith(version))
1045
13382.3.1 by Julian Edwards
Add a failing test to check setting overrides from the queue script.
1046
    def test_override_works_with_PackageCopyJob(self):
1047
        # "Sync" PackageUploads can be overridden just like sources,
1048
        # test that here.
1049
        new_component = self.factory.makeComponent()
1050
        new_section = self.factory.makeSection()
1051
        pocket = PackagePublishingPocket.RELEASE
1052
        upload = self.factory.makeCopyJobPackageUpload(target_pocket=pocket)
1053
        action = self.makeQueueActionOverride(
1054
            upload, new_component, new_section,
1055
            distroseries=upload.distroseries)
1056
        # Patch this out because it uses data we don't have in the test;
1057
        # it's unnecessary anyway.
1058
        self.patch(action, "displayTitle", FakeMethod)
13382.3.5 by Julian Edwards
Fix lint.
1059
        action.terms = ["source", str(upload.id)]
13382.3.1 by Julian Edwards
Add a failing test to check setting overrides from the queue script.
1060
        self.layer.txn.commit()
1061
        self.layer.switchDbUser(config.uploadqueue.dbuser)
1062
        action.initialize()
1063
        action.run()
1064
1065
        # Overriding a sync means putting the overrides in the job itself.
13382.3.4 by Julian Edwards
Fix dumb remaining errors.
1066
        self.assertEqual(
1067
            new_component.name, upload.package_copy_job.component_name)
1068
        self.assertEqual(
1069
            new_section.name, upload.package_copy_job.section_name)
13382.3.1 by Julian Edwards
Add a failing test to check setting overrides from the queue script.
1070
13277.2.2 by Jeroen Vermeulen
Fix the upload tag in the queue script for copy-job uploads.
1071
    def test_makeTag_returns_S_for_source_upload(self):
1072
        upload = self.factory.makeSourcePackageUpload()
1073
        self.assertEqual('S-', self.makeQueueAction(upload)._makeTag(upload))
1074
1075
    def test_makeTag_returns_B_for_binary_upload(self):
1076
        upload = self.factory.makeBuildPackageUpload()
1077
        self.assertEqual('-B', self.makeQueueAction(upload)._makeTag(upload))
1078
1079
    def test_makeTag_returns_SB_for_mixed_upload(self):
1080
        upload = self.factory.makeSourcePackageUpload()
1081
        upload.addBuild(self.factory.makeBinaryPackageBuild())
1082
        self.assertEqual('SB', self.makeQueueAction(upload)._makeTag(upload))
1083
1084
    def test_makeTag_returns_X_for_copy_job_upload(self):
1085
        upload = self.factory.makeCopyJobPackageUpload()
1086
        self.assertEqual('X-', self.makeQueueAction(upload)._makeTag(upload))
1087
1088
    def test_makeTag_returns_dashes_for_custom_upload(self):
1089
        upload = self.factory.makeCustomPackageUpload()
1090
        self.assertEqual('--', self.makeQueueAction(upload)._makeTag(upload))
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
1091
1092
    def test_displayInfo_displays_PackageUpload_with_source(self):
13211.2.5 by Jeroen Vermeulen
Review changes.
1093
        # displayInfo can display a source package upload.
1094
        upload = self.factory.makeSourcePackageUpload()
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
1095
        action = self.makeQueueAction(upload)
1096
        action.displayInfo(upload)
1097
        self.assertNotEqual(0, action.display.call_count)
1098
1099
    def test_displayInfo_displays_PackageUpload_with_PackageCopyJob(self):
13211.2.5 by Jeroen Vermeulen
Review changes.
1100
        # displayInfo can display a copy-job package upload.
1101
        upload = self.factory.makeCopyJobPackageUpload()
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
1102
        action = self.makeQueueAction(upload)
1103
        action.displayInfo(upload)
1104
        self.assertNotEqual(0, action.display.call_count)
1105
1106
11545.2.1 by Julian Edwards
add failing test
1107
class TestQueuePageClosingBugs(TestCaseWithFactory):
1108
    # The distroseries +queue page can close bug when accepting
1109
    # packages.  Unit tests for that belong here.
1110
11545.2.5 by Julian Edwards
LaunchpadFunctionalLayer -> DatabaseFunctionalLayer
1111
    layer = DatabaseFunctionalLayer
11545.2.1 by Julian Edwards
add failing test
1112
1113
    def test_close_bugs_for_sourcepackagerelease_with_private_bug(self):
1114
        # lp.soyuz.scripts.processaccepted.close_bugs_for_sourcepackagerelease
1115
        # should work with private bugs where the person using the queue
1116
        # page doesn't have access to it.
11545.2.2 by Julian Edwards
remove security on bugs when closing them via package uploads, in case the bug is private. This is not ideal but is very low risk.
1117
        changes_file_template = "Format: 1.7\nLaunchpad-bugs-fixed: %s\n"
11545.2.3 by Julian Edwards
Tim's review comments and other improvements
1118
        # changelog_entry is required for an assertion inside the function
1119
        # we're testing.
1120
        spr = self.factory.makeSourcePackageRelease(changelog_entry="blah")
11545.2.1 by Julian Edwards
add failing test
1121
        archive_admin = self.factory.makePerson()
11545.2.3 by Julian Edwards
Tim's review comments and other improvements
1122
        bug = self.factory.makeBug(private=True)
1123
        bug_task = self.factory.makeBugTask(target=spr.sourcepackage, bug=bug)
11545.2.1 by Julian Edwards
add failing test
1124
        changes = StringIO(changes_file_template % bug.id)
11545.2.3 by Julian Edwards
Tim's review comments and other improvements
1125
11545.2.1 by Julian Edwards
add failing test
1126
        with person_logged_in(archive_admin):
11545.2.3 by Julian Edwards
Tim's review comments and other improvements
1127
            # The archive admin user can't normally see this bug.
1128
            self.assertRaises(ForbiddenAttribute, bug, 'status')
1129
            # But the bug closure should work.
11545.2.1 by Julian Edwards
add failing test
1130
            close_bugs_for_sourcepackagerelease(spr, changes)
11545.2.3 by Julian Edwards
Tim's review comments and other improvements
1131
1132
        # Verify it was closed.
1133
        with celebrity_logged_in("admin"):
11545.2.2 by Julian Edwards
remove security on bugs when closing them via package uploads, in case the bug is private. This is not ideal but is very low risk.
1134
            self.assertEqual(bug_task.status, BugTaskStatus.FIXRELEASED)
11545.2.1 by Julian Edwards
add failing test
1135
1136
13211.2.1 by Jeroen Vermeulen
Prepare queue script and +queue page for copy-job package uploads.
1137
class TestQueueToolInJail(TestQueueBase, TestCase):
3500.3.46 by Celso Providelo
review comments, r=spiv
1138
    layer = LaunchpadZopelessLayer
1139
    dbuser = config.uploadqueue.dbuser
1140
1141
    def setUp(self):
1142
        """Create contents in disk for librarian sampledata.
1143
1144
        Setup and chdir into a temp directory, a jail, where we can
3500.3.48 by Celso Providelo
split workarround task from bug #62976 into bug #65052, so this branch is supposed to implement only the workaround required to fix the last, the former still oppened. Also some review comments applyed, r=spiv
1145
        control the file creation properly
3500.3.46 by Celso Providelo
review comments, r=spiv
1146
        """
3500.3.48 by Celso Providelo
split workarround task from bug #62976 into bug #65052, so this branch is supposed to implement only the workaround required to fix the last, the former still oppened. Also some review comments applyed, r=spiv
1147
        fillLibrarianFile(1, content='One')
1148
        fillLibrarianFile(52, content='Fifty-Two')
3500.3.46 by Celso Providelo
review comments, r=spiv
1149
        self._home = os.path.abspath('')
1150
        self._jail = tempfile.mkdtemp()
1151
        os.chdir(self._jail)
3691.357.9 by Stuart Bishop
Make test_queue.py tests connect as the correct database user
1152
        TestQueueBase.setUp(self)
3500.3.46 by Celso Providelo
review comments, r=spiv
1153
1154
    def tearDown(self):
1155
        """Remove test contents from disk.
1156
1157
        chdir back to the previous path (home) and remove the temp
1158
        directory used as jail.
1159
        """
1160
        os.chdir(self._home)
11737.4.1 by Robert Collins
Finish transitioning LibrarianTestSetup to LibrarianServerFixture, drop the singleton. \o/
1161
        LibrarianLayer.librarian_fixture.clear()
3500.3.46 by Celso Providelo
review comments, r=spiv
1162
        shutil.rmtree(self._jail)
1163
1164
    def _listfiles(self):
1165
        """Return a list of files present in jail."""
1166
        return os.listdir(self._jail)
1167
4989.2.2 by Julian Edwards
Fix lint, as per sinzui's review.
1168
    def _getsha1(self, filename):
3935.1.2 by Julian Edwards
Address reviewer comments:
1169
        """Return a sha1 hex digest of a file"""
10293.1.1 by Barry Warsaw, Max Bowsher
Switch from using sha and md5 to hashlib. Also use hashlib.sha256 instead of
1170
        file_sha = hashlib.sha1()
13211.1.1 by Jeroen Vermeulen
Lint.
1171
        opened_file = open(filename, "r")
3935.1.2 by Julian Edwards
Address reviewer comments:
1172
        for chunk in filechunks(opened_file):
1173
            file_sha.update(chunk)
1174
        opened_file.close()
1175
        return file_sha.hexdigest()
1176
3500.3.46 by Celso Providelo
review comments, r=spiv
1177
    def testFetchActionByIDDoNotOverwriteFilesystem(self):
1178
        """Check if queue fetch action doesn't overwrite files.
1179
1180
        Since we allow existence of duplications in NEW and UNAPPROVED
1181
        queues, we are able to fetch files from queue items and they'd
1182
        get overwritten causing obscure problems.
1183
1184
        Instead of overwrite a file in the working directory queue will
1185
        fail, raising a CommandRunnerError.
3935.1.1 by Julian Edwards
Fix bug 67014 - "queue fetch safety catch is slightly too stiff"
1186
1187
        bug 67014: Don't complain if files are the same
3500.3.46 by Celso Providelo
review comments, r=spiv
1188
        """
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
1189
        self.execute_command('fetch 1')
3500.3.46 by Celso Providelo
review comments, r=spiv
1190
        self.assertEqual(
1191
            ['mozilla-firefox_0.9_i386.changes'], self._listfiles())
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
1192
3935.1.2 by Julian Edwards
Address reviewer comments:
1193
        # checksum the existing file
1194
        existing_sha1 = self._getsha1(self._listfiles()[0])
3500.3.48 by Celso Providelo
split workarround task from bug #62976 into bug #65052, so this branch is supposed to implement only the workaround required to fix the last, the former still oppened. Also some review comments applyed, r=spiv
1195
3935.1.1 by Julian Edwards
Fix bug 67014 - "queue fetch safety catch is slightly too stiff"
1196
        # fetch will NOT raise and not overwrite the file in disk
1197
        self.execute_command('fetch 1')
3500.3.46 by Celso Providelo
review comments, r=spiv
1198
3935.1.2 by Julian Edwards
Address reviewer comments:
1199
        # checksum file again
1200
        new_sha1 = self._getsha1(self._listfiles()[0])
1201
1202
        # Check that the file has not changed (we don't care if it was
1203
        # re-written, just that it's not changed)
4989.2.2 by Julian Edwards
Fix lint, as per sinzui's review.
1204
        self.assertEqual(existing_sha1, new_sha1)
3935.1.2 by Julian Edwards
Address reviewer comments:
1205
1206
    def testFetchActionRaisesErrorIfDifferentFileAlreadyFetched(self):
1207
        """Check that fetching a file that has already been fetched
1208
        raises an error if they are not the same file.  (bug 67014)
1209
        """
4989.2.2 by Julian Edwards
Fix lint, as per sinzui's review.
1210
        CLOBBERED = "you're clobbered"
3935.1.2 by Julian Edwards
Address reviewer comments:
1211
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
1212
        self.execute_command('fetch 1')
3935.1.2 by Julian Edwards
Address reviewer comments:
1213
        self.assertEqual(
1214
            ['mozilla-firefox_0.9_i386.changes'], self._listfiles())
3500.3.48 by Celso Providelo
split workarround task from bug #62976 into bug #65052, so this branch is supposed to implement only the workaround required to fix the last, the former still oppened. Also some review comments applyed, r=spiv
1215
3935.1.1 by Julian Edwards
Fix bug 67014 - "queue fetch safety catch is slightly too stiff"
1216
        # clobber the existing file, fetch it again and expect an exception
13211.1.1 by Jeroen Vermeulen
Lint.
1217
        f = open(self._listfiles()[0], "w")
3935.1.2 by Julian Edwards
Address reviewer comments:
1218
        f.write(CLOBBERED)
3935.1.1 by Julian Edwards
Fix bug 67014 - "queue fetch safety catch is slightly too stiff"
1219
        f.close()
1220
4785.3.7 by Jeroen Vermeulen
Removed whitespace at ends of lines
1221
        self.assertRaises(
3935.1.1 by Julian Edwards
Fix bug 67014 - "queue fetch safety catch is slightly too stiff"
1222
            CommandRunnerError, self.execute_command, 'fetch 1')
1223
3935.1.2 by Julian Edwards
Address reviewer comments:
1224
        # make sure the file has not changed
13211.1.1 by Jeroen Vermeulen
Lint.
1225
        f = open(self._listfiles()[0], "r")
3935.1.2 by Julian Edwards
Address reviewer comments:
1226
        line = f.read()
1227
        f.close()
1228
4989.2.2 by Julian Edwards
Fix lint, as per sinzui's review.
1229
        self.assertEqual(CLOBBERED, line)
3935.1.2 by Julian Edwards
Address reviewer comments:
1230
3500.3.46 by Celso Providelo
review comments, r=spiv
1231
    def testFetchActionByNameDoNotOverwriteFilesystem(self):
1232
        """Same as testFetchActionByIDDoNotOverwriteFilesystem
1233
1234
        The sampledata provides duplicated 'cnews' entries, filesystem
1235
        conflict will happen inside the same batch,
1236
1237
        Queue will fetch the oldest and raise.
1238
        """
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
1239
        self.assertRaises(
3500.3.46 by Celso Providelo
review comments, r=spiv
1240
            CommandRunnerError, self.execute_command, 'fetch cnews',
1241
            queue_name='unapproved', suite_name='breezy-autotest')
1242
1243
        self.assertEqual(['netapplet-1.0.0.tar.gz'], self._listfiles())
3500.3.45 by Celso Providelo
Fix bug #62976 (accepting duplicated queue entries within a batch, refuse to overwrite files on disk when fetching duplicated queue items)
1244
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
1245
    def testQueueFetch(self):
1246
        """Check that a basic fetch operation works."""
1247
        FAKE_CHANGESFILE_CONTENT = "Fake Changesfile"
1248
        FAKE_DEB_CONTENT = "Fake DEB"
1249
        fillLibrarianFile(1, FAKE_CHANGESFILE_CONTENT)
6221.2.5 by Celso Providelo
Fixing test failures and add a missing DB permission.
1250
        fillLibrarianFile(90, FAKE_DEB_CONTENT)
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
1251
        self.execute_command('fetch pmount')
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
1252
1253
        # Check the files' names.
4898.1.2 by Julian Edwards
Apply intellectronica and bac's review comments.
1254
        files = sorted(self._listfiles())
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
1255
        self.assertEqual(
6221.2.5 by Celso Providelo
Fixing test failures and add a missing DB permission.
1256
            ['netapplet-1.0.0.tar.gz', 'pmount_1.0-1_all.deb'],
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
1257
            files)
1258
1259
        # Check the files' contents.
1260
        changes_file = open('netapplet-1.0.0.tar.gz')
1261
        self.assertEqual(changes_file.read(), FAKE_CHANGESFILE_CONTENT)
1262
        changes_file.close()
6221.2.5 by Celso Providelo
Fixing test failures and add a missing DB permission.
1263
        debfile = open('pmount_1.0-1_all.deb')
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
1264
        self.assertEqual(debfile.read(), FAKE_DEB_CONTENT)
1265
        debfile.close()
1266
4500.1.4 by Julian Edwards
First batch of tests added.
1267
    def testFetchMultipleItems(self):
1268
        """Check if fetching multiple items at once works.
1269
1270
        We can specify multiple items to fetch, even mixing IDs and names.
1271
        e.g. queue fetch alsa-utils 1 3
1272
        """
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
1273
        self.execute_command('fetch 3 mozilla-firefox')
4500.1.11 by Julian Edwards
Fix a test that was failing on PQM but not locally.
1274
        files = self._listfiles()
1275
        files.sort()
4500.1.4 by Julian Edwards
First batch of tests added.
1276
        self.assertEqual(
1277
            ['mozilla-firefox_0.9_i386.changes', 'netapplet-1.0.0.tar.gz'],
4500.1.11 by Julian Edwards
Fix a test that was failing on PQM but not locally.
1278
            files)