class TestBuildNotifications(TrialTestCase): layer = LaunchpadZopelessLayer def setUp(self): super(TestBuildNotifications, self).setUp() from lp.testing.factory import LaunchpadObjectFactory self.factory = LaunchpadObjectFactory() def prepareBehavior(self, fake_successful_upload=False): self.queue_record = self.factory.makeSourcePackageRecipeBuildJob() build = self.queue_record.specific_job.build build.updateStatus(BuildStatus.FULLYBUILT) if fake_successful_upload: removeSecurityProxy(build).verifySuccessfulUpload = FakeMethod( result=True) # We overwrite the buildmaster root to use a temp directory. tempdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tempdir) self.upload_root = tempdir tmp_builddmaster_root = """ [builddmaster] root: %s """ % self.upload_root config.push('tmp_builddmaster_root', tmp_builddmaster_root) self.addCleanup(config.pop, 'tmp_builddmaster_root') self.queue_record.builder = self.factory.makeBuilder() slave = WaitingSlave('BuildStatus.OK') return BuilderInteractor.getBuildBehavior(self.queue_record, self.queue_record.builder, slave) def assertDeferredNotifyCount(self, status, behavior, expected_count): d = behavior.handleStatus(self.queue_record, status, {'filemap': {}}) def cb(result): self.assertEqual(expected_count, len(pop_notifications())) d.addCallback(cb) return d def test_handleStatus_PACKAGEFAIL(self): """Failing to build the package immediately sends a notification.""" return self.assertDeferredNotifyCount("PACKAGEFAIL", self.prepareBehavior(), 1) def test_handleStatus_OK(self): """Building the source package does _not_ immediately send mail. (The archive uploader mail send one later. """ return self.assertDeferredNotifyCount("OK", self.prepareBehavior(), 0) def test_handleStatus_OK_successful_upload(self): return self.assertDeferredNotifyCount("OK", self.prepareBehavior(True), 0)
class TestBuildNotifications(TrialTestCase): layer = LaunchpadZopelessLayer def setUp(self): super(TestBuildNotifications, self).setUp() from lp.testing.factory import LaunchpadObjectFactory self.factory = LaunchpadObjectFactory() def prepareBehavior(self, fake_successful_upload=False): self.queue_record = self.factory.makeSourcePackageRecipeBuildJob() build = self.queue_record.specific_job.build build.updateStatus(BuildStatus.FULLYBUILT) if fake_successful_upload: removeSecurityProxy(build).verifySuccessfulUpload = FakeMethod(result=True) # We overwrite the buildmaster root to use a temp directory. tempdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tempdir) self.upload_root = tempdir tmp_builddmaster_root = ( """ [builddmaster] root: %s """ % self.upload_root ) config.push("tmp_builddmaster_root", tmp_builddmaster_root) self.addCleanup(config.pop, "tmp_builddmaster_root") self.queue_record.builder = self.factory.makeBuilder() slave = WaitingSlave("BuildStatus.OK") return BuilderInteractor.getBuildBehavior(self.queue_record, self.queue_record.builder, slave) def assertDeferredNotifyCount(self, status, behavior, expected_count): d = behavior.handleStatus(self.queue_record, status, {"filemap": {}}) def cb(result): self.assertEqual(expected_count, len(pop_notifications())) d.addCallback(cb) return d def test_handleStatus_PACKAGEFAIL(self): """Failing to build the package immediately sends a notification.""" return self.assertDeferredNotifyCount("PACKAGEFAIL", self.prepareBehavior(), 1) def test_handleStatus_OK(self): """Building the source package does _not_ immediately send mail. (The archive uploader mail send one later. """ return self.assertDeferredNotifyCount("OK", self.prepareBehavior(), 0) def test_handleStatus_OK_successful_upload(self): return self.assertDeferredNotifyCount("OK", self.prepareBehavior(True), 0)