# HG changeset patch # User mgood # Date 1237766897 0 # Node ID 23b7bdfb878d7feb00fcd313eb9c181ad768bc3a # Parent b72243e5231723f78bf91067072e535fd1f0b691 Make notifier mocking and called state testing clearer diff --git a/bitten/tests/notify.py b/bitten/tests/notify.py --- a/bitten/tests/notify.py +++ b/bitten/tests/notify.py @@ -40,37 +40,36 @@ """unit tests for BittenNotify dispatcher class""" def setUp(self): BittenNotifyBaseTest.setUp(self) - #fixture - self.state = [False] - self.email = Mock(notify = lambda buildInfo: \ - self.state.__setitem__(0,True)) - self.dispatcher = BittenNotify(self.env) - self.dispatcher.email = self.email - self.failed_build = Build(self.env, status = Build.FAILURE) - self.successful_build = Build(self.env, status = Build.SUCCESS) + self.notify_was_called = False + def notify(build_info): + self.notify_was_called = True + self.dispatcher = Mock(BittenNotify, self.env, + email=Mock(notify=notify)) + self.failed_build = Build(self.env, status=Build.FAILURE) + self.successful_build = Build(self.env, status=Build.SUCCESS) def test_do_notify_on_failed_build(self): self.env.config.set(CONFIG_SECTION, NOTIFY_ON_FAILURE, 'true') self.dispatcher.notify(self.failed_build) - self.assertTrue(self.state[0], + self.assertTrue(self.notify_was_called, 'notifier should be called for failed builds.') def test_do_not_notify_on_failed_build(self): self.env.config.set(CONFIG_SECTION, NOTIFY_ON_FAILURE, 'false') self.dispatcher.notify(self.failed_build) - self.assertFalse(self.state[0], + self.assertFalse(self.notify_was_called, 'notifier should not be called for failed build.') def test_do_notify_on_successful_build(self): self.env.config.set(CONFIG_SECTION, NOTIFY_ON_SUCCESS, 'true') self.dispatcher.notify(self.successful_build) - self.assertTrue(self.state[0], + self.assertTrue(self.notify_was_called, 'notifier should be called for successful builds when configured.') def test_do_not_notify_on_successful_build(self): self.env.config.set(CONFIG_SECTION, NOTIFY_ON_SUCCESS, 'false') self.dispatcher.notify(self.successful_build) - self.assertFalse(self.state[0], + self.assertFalse(self.notify_was_called, 'notifier shouldn\'t be called for successful build.')