~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/buildmaster/tests/test_packagebuild.py

  • Committer: Raphael Badin
  • Date: 2012-01-06 08:27:55 UTC
  • mfrom: (14513.5.4 builder-history-lfa)
  • mto: This revision was merged to the branch mainline in revision 14654.
  • Revision ID: raphael.badin@canonical.com-20120106082755-95a0eh6nakv5hj3b
Merge devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Tests for `IPackageBuild`."""
12
12
import tempfile
13
13
 
14
14
from storm.store import Store
 
15
from testtools.deferredruntest import AsynchronousDeferredRunTest
15
16
from zope.component import getUtility
16
17
from zope.security.interfaces import Unauthorized
17
18
from zope.security.proxy import removeSecurityProxy
26
27
    IPackageBuildSet,
27
28
    IPackageBuildSource,
28
29
    )
 
30
from lp.buildmaster.model.builder import BuilderSlave
29
31
from lp.buildmaster.model.buildfarmjob import BuildFarmJob
30
32
from lp.buildmaster.model.packagebuild import PackageBuild
 
33
from lp.buildmaster.testing import BuilddManagerTestFixture
31
34
from lp.buildmaster.tests.mock_slaves import WaitingSlave
32
35
from lp.registry.interfaces.pocket import PackagePublishingPocket
33
36
from lp.services.config import config
281
284
 
282
285
 
283
286
class TestHandleStatusMixin:
284
 
    """Tests for `IPackageBuild`s handleStatus method.
285
 
 
286
 
    This should be run with a Trial TestCase.
287
 
    """
 
287
    """Tests for `IPackageBuild`s handleStatus method."""
288
288
 
289
289
    layer = LaunchpadZopelessLayer
 
290
    run_tests_with = AsynchronousDeferredRunTest.make_factory(timeout=20)
290
291
 
291
292
    def makeBuild(self):
292
293
        """Allow classes to override the build with which the test runs."""
303
304
        self.build.buildqueue_record.setDateStarted(UTC_NOW)
304
305
        self.slave = WaitingSlave('BuildStatus.OK')
305
306
        self.slave.valid_file_hashes.append('test_file_hash')
306
 
        builder.setSlaveForTesting(self.slave)
 
307
        self.patch(BuilderSlave, 'makeBuilderSlave', FakeMethod(self.slave))
307
308
 
308
309
        # We overwrite the buildmaster root to use a temp directory.
309
310
        tempdir = tempfile.mkdtemp()
321
322
        removeSecurityProxy(self.build).verifySuccessfulUpload = FakeMethod(
322
323
            result=True)
323
324
 
 
325
        self.useFixture(BuilddManagerTestFixture())
 
326
 
324
327
    def assertResultCount(self, count, result):
325
328
        self.assertEquals(
326
329
            1, len(os.listdir(os.path.join(self.upload_root, result))))
344
347
        def got_status(ignored):
345
348
            self.assertEqual(BuildStatus.FAILEDTOUPLOAD, self.build.status)
346
349
            self.assertResultCount(0, "failed")
347
 
            self.assertIdentical(None, self.build.buildqueue_record)
 
350
            self.assertIs(None, self.build.buildqueue_record)
348
351
 
349
352
        d = self.build.handleStatus('OK', None, {
350
353
            'filemap': {'/tmp/myfile.py': 'test_file_hash'},
365
368
 
366
369
    def test_handleStatus_OK_sets_build_log(self):
367
370
        # The build log is set during handleStatus.
368
 
        removeSecurityProxy(self.build).log = None
 
371
        with BuilddManagerTestFixture.extraSetUp():
 
372
            removeSecurityProxy(self.build).log = None
369
373
        self.assertEqual(None, self.build.log)
370
374
        d = self.build.handleStatus('OK', None, {
371
375
                'filemap': {'myfile.py': 'test_file_hash'},
386
390
 
387
391
        def got_status(ignored):
388
392
            if expected_notification:
389
 
                self.failIf(
390
 
                    len(pop_notifications()) == 0,
391
 
                    "No notifications received")
 
393
                self.assertNotEqual(
 
394
                    0, len(pop_notifications()), "No notifications received.")
392
395
            else:
393
 
                self.failIf(
394
 
                    len(pop_notifications()) > 0,
395
 
                    "Notifications received")
396
 
 
 
396
                self.assertContentEqual([], pop_notifications())
397
397
        d = self.build.handleStatus(status, None, {})
398
398
        return d.addCallback(got_status)
399
399
 
408
408
 
409
409
    def test_date_finished_set(self):
410
410
        # The date finished is updated during handleStatus_OK.
411
 
        removeSecurityProxy(self.build).date_finished = None
 
411
        with BuilddManagerTestFixture.extraSetUp():
 
412
            removeSecurityProxy(self.build).date_finished = None
 
413
 
412
414
        self.assertEqual(None, self.build.date_finished)
413
415
        d = self.build.handleStatus('OK', None, {
414
416
                'filemap': {'myfile.py': 'test_file_hash'},