From 8c8e5ae926e0009743fe92dccb588783640a6022 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 17 Aug 2011 11:08:07 +0100 Subject: * Reminder notifications now take the same path to notify as initial alerts * Threading tidied -- processor will not do anything unless the timer has frozen * Person#send_alert now tidied and merged with alert_changed * POP3 server only shows alerts relevant to the user * Server now defaults to using an in-memory SQLite database (good for testing) * Server initializes a blank mauve config. * Tests tidied up --- test/tc_mauve_alert.rb | 110 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 102 insertions(+), 8 deletions(-) (limited to 'test/tc_mauve_alert.rb') diff --git a/test/tc_mauve_alert.rb b/test/tc_mauve_alert.rb index ef80424..f79859f 100644 --- a/test/tc_mauve_alert.rb +++ b/test/tc_mauve_alert.rb @@ -1,16 +1,30 @@ $:.unshift "../lib" -require 'test/unit' + +require 'th_mauve' +require 'th_mauve_resolv' + require 'mauve/alert' +require 'mauve/proto' +require 'mauve/server' require 'mauve/configuration' require 'mauve/configuration_builder' -require 'th_mauve_resolv' -require 'pp' +require 'mauve/configuration_builders' -class TcMauveAlert < Test::Unit::TestCase +class TcMauveAlert < Mauve::UnitTest + include Mauve - def test_source_list + def setup + super + setup_database + end + + def teardown + teardown_database + super + end + def test_source_list config=< "test-host", + :alert_id => "test" ) + + a.raise! + end + + def test_alert_reception + Server.instance.setup + + update = Proto::AlertUpdate.new + update.source = "test-host" + message = Proto::Alert.new + update.alert << message + message.id = "test1" + message.summary = "test summary" + message.detail = "test detail" + message.raise_time = Time.now.to_i + message.clear_time = Time.now.to_i+5.minutes + + Alert.receive_update(update, Time.now, "127.0.0.1") + + a = Alert.first(:alert_id => 'test1') + + assert(a.raised?) + assert_equal("test-host", a.subject) + assert_equal("test-host", a.source) + assert_equal("test detail", a.detail) + assert_equal("test summary", a.summary) + + end + + def test_alert_ackowledgement + person = Mauve::Person.new + person.username = "test-user" + + Server.instance.setup + + Mauve::Configuration.current.people[person.username] = person + + alert = Alert.new( + :alert_id => "test-acknowledge", + :source => "test", + :subject => "test" + ) + alert.raise! + assert(alert.raised?) + + alert.acknowledge!(person, Time.now + 3.minutes) + assert(alert.acknowledged?) + + next_alert = Alert.find_next_with_event + assert_equal(next_alert.id, alert.id) + assert_equal(Time.now+3.minutes, next_alert.due_at) + + Timecop.freeze(next_alert.due_at) + + alert.poll + + # + # The alert should unacknowledge itself. + # + assert(!alert.acknowledged?) + + + end + end -- cgit v1.2.1