aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-04-27 11:12:27 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-04-27 11:12:27 +0100
commitdada535a41cba45be0eff77381d6c7e19ab49f51 (patch)
treef33ab8706c38f278fbdec539e69874d72a9e1b74 /test
parentffb9ad5713f0f7b895ec142028abae16d824e3b9 (diff)
Added better time-based people list polling, and added a "calendar" method to
the config to easily generate Procs to call for people_lists.
Diffstat (limited to 'test')
-rw-r--r--test/tc_mauve_notification.rb37
-rw-r--r--test/tc_mauve_people_list.rb31
2 files changed, 55 insertions, 13 deletions
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