From 4f6ff88393027210d8710bee1d2b1b329a426922 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Fri, 8 Jun 2012 10:31:25 +0100 Subject: Fixed notify_when_on_holiday/off_sick flags in configuration + added tests. --- test/tc_mauve_notification.rb | 139 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) (limited to 'test') diff --git a/test/tc_mauve_notification.rb b/test/tc_mauve_notification.rb index b8fb904..ea041f8 100644 --- a/test/tc_mauve_notification.rb +++ b/test/tc_mauve_notification.rb @@ -339,13 +339,17 @@ end class TcMauveNotification < Mauve::UnitTest include Mauve + include WebMock::API def setup super setup_database + WebMock.disable_net_connect! end def teardown + WebMock.reset! + WebMock.allow_net_connect! teardown_database super end @@ -816,6 +820,7 @@ alert_group("test") { } EOF + Configuration.current = ConfigurationBuilder.parse(config) notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue @@ -862,4 +867,138 @@ EOF end end + + def test_notify_when_on_holiday + + attendees = %w(test1 test2) + + stub_request(:get, "http://localhost/calendar/api/bank_holidays/2011-08-01"). + to_return(:status => 200, :body => YAML.dump([])) + + stub_request(:get, "http://localhost/calendar/api/attendees/sick_period/2011-08-01T00:00:00"). + to_return(:status => 200, :body => YAML.dump([])) + + stub_request(:get, "http://localhost/calendar/api/attendees/staff_holiday/2011-08-01T00:00:00"). + to_return(:status => 200, :body => YAML.dump(attendees)) + + config=< "test", + :source => "test", + :subject => "test" + ) + + assert_equal("test", alert.alert_group.name) + + alert.raise! + assert(alert.raised?) + assert_equal(1, notification_buffer.size, "Wrong number of notifications sent") + sent = notification_buffer.pop + assert_equal("test1@example.com", sent[2]) + end + + def test_notify_when_off_sick + attendees = %w(test1 test2) + + stub_request(:get, "http://localhost/calendar/api/bank_holidays/2011-08-01"). + to_return(:status => 200, :body => YAML.dump([])) + + stub_request(:get, "http://localhost/calendar/api/attendees/sick_period/2011-08-01T00:00:00"). + to_return(:status => 200, :body => YAML.dump(attendees)) + + stub_request(:get, "http://localhost/calendar/api/attendees/staff_holiday/2011-08-01T00:00:00"). + to_return(:status => 200, :body => YAML.dump([])) + + config=< "test", + :source => "test", + :subject => "test" + ) + + assert_equal("test", alert.alert_group.name) + + alert.raise! + assert(alert.raised?) + assert_equal(1, notification_buffer.size, "Wrong number of notifications sent") + sent = notification_buffer.pop + assert_equal("test2@example.com", sent[2]) + end + end -- cgit v1.2.1