aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog4
-rw-r--r--lib/mauve/configuration.rb4
-rw-r--r--lib/mauve/notification.rb3
-rw-r--r--lib/mauve/people_list.rb4
-rw-r--r--test/tc_mauve_notification.rb37
-rw-r--r--test/tc_mauve_people_list.rb31
6 files changed, 66 insertions, 17 deletions
diff --git a/debian/changelog b/debian/changelog
index a271f9b..f41e76e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,8 +2,10 @@ mauvealert (3.8.2) stable; urgency=low
* Reverted bad changes to mauveserver + example.conf
* Added default options for a person
+ * Added calendar check for a people_list
+ * Added a time at which to check the people in a people_list
- -- Patrick J Cherry <patrick@bytemark.co.uk> Fri, 27 Apr 2012 10:58:56 +0100
+ -- Patrick J Cherry <patrick@bytemark.co.uk> Fri, 27 Apr 2012 11:00:21 +0100
mauvealert (3.8.1) stable; urgency=low
diff --git a/lib/mauve/configuration.rb b/lib/mauve/configuration.rb
index 3a8f9cc..8a0b982 100644
--- a/lib/mauve/configuration.rb
+++ b/lib/mauve/configuration.rb
@@ -165,5 +165,9 @@ module Mauve
@max_acknowledgement_time = arg
end
+ def calendar=(x)
+ lambda{|at| CalendarInterface.get_attendees(x,at)}
+ end
+
end
end
diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb
index 8a5d241..899972b 100644
--- a/lib/mauve/notification.rb
+++ b/lib/mauve/notification.rb
@@ -122,8 +122,9 @@ module Mauve
#
def no_one_in(people_list)
return true unless Configuration.current.people_lists.has_key?(people_list)
+ @test_time = @time if @test_time.nil?
- return Configuration.current.people_lists[people_list].people.empty?
+ return Configuration.current.people_lists[people_list].people(@test_time).empty?
end
# Returns true if the current hour is in the list of hours given.
diff --git a/lib/mauve/people_list.rb b/lib/mauve/people_list.rb
index 0433034..f632f78 100644
--- a/lib/mauve/people_list.rb
+++ b/lib/mauve/people_list.rb
@@ -63,9 +63,9 @@ module Mauve
# Return the array of people
#
# @return [Array]
- def people
+ def people(at = Time.now)
l = list.collect do |name|
- name.is_a?(Proc) ? name.call : name
+ name.is_a?(Proc) ? name.call(at) : name
end.flatten.compact.uniq.collect do |name|
Configuration.current.people[name]
end.compact
diff --git a/test/tc_mauve_notification.rb b/test/tc_mauve_notification.rb
index 7a71c47..21ff41e 100644
--- a/test/tc_mauve_notification.rb
+++ b/test/tc_mauve_notification.rb
@@ -7,17 +7,22 @@ require 'mauve/configuration'
require 'mauve/configuration_builder'
require 'mauve/configuration_builders'
require 'mauve/mauve_time'
+require 'webmock'
class TcMauveDuringRunner < 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
@@ -187,6 +192,38 @@ EOF
assert(!dr.send(:no_one_in, "not empty"))
end
+ def test_no_one_in_with_calendar
+ config=<<EOF
+bytemark_calendar_url "http://localhost"
+person "test1"
+person "test2"
+
+people_list "support", calendar("support_shift")
+EOF
+
+ Configuration.current = ConfigurationBuilder.parse(config)
+
+ stub_request(:get, "http://localhost/api/attendees/support_shift/2011-08-01T00:00:00").
+ to_return(:status => 200, :body => YAML.dump(%w(test1 test2)))
+
+ stub_request(:get, "http://localhost/api/attendees/support_shift/2011-08-01T00:05:00").
+ to_return(:status => 200, :body => YAML.dump([]))
+
+ dr = DuringRunner.new(Time.now)
+ assert(!dr.send(:no_one_in, "support"))
+
+ # advance by 5 minutes, and try again -- we should get the same answer.
+ Timecop.freeze(Time.now + 5.minutes)
+ assert(!dr.send(:no_one_in, "support"))
+
+ # However a new runner should return true.
+ dr = DuringRunner.new(Time.now)
+ assert(dr.send(:no_one_in, "support"))
+ #
+ # We expect a warning about an empty list.
+ logger_pop
+ end
+
end
class TcMauveNotification < Mauve::UnitTest
diff --git a/test/tc_mauve_people_list.rb b/test/tc_mauve_people_list.rb
index fd8bda9..78586d2 100644
--- a/test/tc_mauve_people_list.rb
+++ b/test/tc_mauve_people_list.rb
@@ -5,28 +5,28 @@ require 'mauve/people_list'
require 'mauve/configuration'
require 'mauve/configuration_builder'
require 'mauve/configuration_builders'
+require 'webmock'
require 'pp'
class TcMauvePeopleList < 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
def test_send_alert
- #
- # Allows us to pick up notifications sent.
- #
- $sent_notifications = []
-
config =<<EOF
notification_method("email") {
debug!
@@ -119,27 +119,32 @@ EOF
end
def test_dynamic_people_list
- #
- # Allows us to pick up notifications sent.
- #
- $sent_notifications = []
-
config =<<EOF
+bytemark_calendar_url "http://localhost"
person "test1"
-
person "test2"
#
# This should oscillate between test1 and test2.
#
-people_list "testers", lambda { $ans = ($ans == "test1" ? "test2" : "test1") }
+people_list "testers", calendar("support_shift")
EOF
Configuration.current = ConfigurationBuilder.parse(config)
+
+ #
+ # Stub HTTP requests to return test1 now, and tes2 later.
+ #
+ stub_request(:get, "http://localhost/api/attendees/support_shift/2011-08-01T00:00:00").
+ to_return(:status => 200, :body => YAML.dump(%w(test1)))
+
+ stub_request(:get, "http://localhost/api/attendees/support_shift/2011-08-01T00:05:00").
+ to_return(:status => 200, :body => YAML.dump(%w(test2)))
+
people_list = Configuration.current.people_lists["testers"]
assert_equal([Configuration.current.people["test1"]], people_list.people)
- assert_equal([Configuration.current.people["test2"]], people_list.people)
+ assert_equal([Configuration.current.people["test2"]], people_list.people(Time.now + 5.minutes))
end
end