From e959c0fe4c887154bbe28c31324fef2975cbe467 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 25 Apr 2012 17:15:49 +0100 Subject: Big update. * Max acknowledgement time is now specified in the config * Calendar interface improved. * holiday_url no longer used -- replaced by notify_when_on_holiday! * added notify_when_off_sick! * Added ability for the calendar to be queried for a list of bank holdays. * Added ability for Time to be given a list of bank holidays to check against. * PeopleLists can now be a Proc, allowing downloading of lists * Person is no longer a struct * Moved the method_missing bit into ObjectBuilder from various sub classes. * Added tests for the calendar interface * Updated tests in other bits. --- test/tc_mauve_alert.rb | 3 +- test/tc_mauve_authentication.rb | 18 ++--- test/tc_mauve_calendar_interface.rb | 155 ++++++++++++++++++++++++++++++++++++ test/tc_mauve_notification.rb | 6 ++ test/tc_mauve_people_list.rb | 25 ++++++ test/tc_mauve_time.rb | 7 ++ test/th_mauve.rb | 5 ++ 7 files changed, 204 insertions(+), 15 deletions(-) create mode 100644 test/tc_mauve_calendar_interface.rb (limited to 'test') diff --git a/test/tc_mauve_alert.rb b/test/tc_mauve_alert.rb index 2b8af6f..3af9075 100644 --- a/test/tc_mauve_alert.rb +++ b/test/tc_mauve_alert.rb @@ -95,8 +95,7 @@ EOF end def test_acknowledge! - person = Mauve::Person.new - person.username = "test-user" + person = Mauve::Person.new("test-user") Server.instance.setup diff --git a/test/tc_mauve_authentication.rb b/test/tc_mauve_authentication.rb index d0f2d4f..c364aca 100644 --- a/test/tc_mauve_authentication.rb +++ b/test/tc_mauve_authentication.rb @@ -26,9 +26,7 @@ class TcMauveAuthentication < Mauve::UnitTest def test_default_auth_always_fails config=< 200, :body => YAML.dump(attendees)) + + config =< 200, :body => YAML.dump(attendees)) + + + config =< 200, :body => YAML.dump(attendees)) + + config =< 301, :body => nil, :headers => {:location => next_url}) + url = next_url + end + + # + # And finally the answer. + # + stub_request(:get, url). + to_return(:status => 200, :body => "OK!", :headers => {}) + + # + # Now do_get should return "OK!" when the maximum number of redirects is set to two. + # + result = nil + assert_nothing_raised{ result = CalendarInterface.__send__(:do_get, "http://localhost/", 2) } + assert_equal("OK!",result) + + # + # do_get should return nil when the maximum number of redirects is set to two. + # + assert_nothing_raised{ result = CalendarInterface.__send__(:do_get, "http://localhost/", 1) } + assert_nil(result) + + # + # Pop the warning about the redirect off the end of the log. + # + logger_pop + end + + def test_do_get_with_cache + url = "http://localhost/" + + # + # This stubs the request to give out the time + # + stub_request(:get, url). + to_return( lambda{ {:status => 200, :body => YAML.dump(Time.now), :headers => {}} } ) + + # + # This reponse should not be cached, the cache-until paramter is "now" + # + assert_equal(Time.now, CalendarInterface.__send__(:do_get_with_cache, url, Time.now)) + + # + # Since the last request wasn't cached, the next one should give back + # "now", and should be cached for the next 10 seconds. + # + Timecop.freeze(Time.now + 5) + assert_equal(Time.now, CalendarInterface.__send__(:do_get_with_cache, url, Time.now + 10)) + + # + # This should have been cached from the last query. + # + Timecop.freeze(Time.now + 5) + assert_equal(Time.now - 5, CalendarInterface.__send__(:do_get_with_cache, url, Time.now + 10)) + + # + # Finally, this should now have expired from the cache. + # + Timecop.freeze(Time.now + 5) + assert_equal(Time.now, CalendarInterface.__send__(:do_get_with_cache, url, Time.now + 10)) + + Timecop.freeze(Time.now + 50) + cache = CalendarInterface.__send__(:clean_cache) + assert(cache.empty?) + end + + +end + + + + + diff --git a/test/tc_mauve_notification.rb b/test/tc_mauve_notification.rb index a447207..d0c2bab 100644 --- a/test/tc_mauve_notification.rb +++ b/test/tc_mauve_notification.rb @@ -442,9 +442,15 @@ people_list("testers", %w(test1 test2)) { alert_group("test") { level URGENT + notify("test1") notify("test2") notify("testers") + + notify("testers") { + every 60 + during { hours_in_day (3) } + } } EOF diff --git a/test/tc_mauve_people_list.rb b/test/tc_mauve_people_list.rb index 2d5da6d..fd8bda9 100644 --- a/test/tc_mauve_people_list.rb +++ b/test/tc_mauve_people_list.rb @@ -117,4 +117,29 @@ EOF end end + + def test_dynamic_people_list + # + # Allows us to pick up notifications sent. + # + $sent_notifications = [] + + config =<