Project

General

Profile

Download (1.62 KB) Statistics
| Branch: | Tag: | Revision:
adb0dfd9 Ohad Levy
require 'test_helper'

class ReportObserverTest < ActiveSupport::TestCase
92ff1eef Lucas Tolchinsky
def setup
# Email recepient
07ad7166 Lucas Tolchinsky
SETTINGS[:administrator] = "admin@example.com"
92ff1eef Lucas Tolchinsky
# Host and Report creation
h = Host.create :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03",
:domain => Domain.find_or_create_by_name("company.com"),
:operatingsystem => Operatingsystem.create(:name => "linux", :major => 389),
:architecture => Architecture.find_or_create_by_name("i386"),
:environment => Environment.find_or_create_by_name("envy"),
:disk => "empty partition"
9c0e127b Paul Kelly
h.update_attribute :owner, User.first if SETTINGS[:ldap]
92ff1eef Lucas Tolchinsky
p = Puppet::Transaction::Report.new
p.save

@report = Report.new :host => h, :log => p, :reported_at => Date.today
end

07ad7166 Lucas Tolchinsky
test "when notification fails, if report has an error a mail to admin should be sent" do
SETTINGS[:failed_report_email_notification] = true
92ff1eef Lucas Tolchinsky
assert_difference 'ActionMailer::Base.deliveries.size' do
@report.status = 16781381 # Error status.
@report.save!
9c0e127b Paul Kelly
@report
92ff1eef Lucas Tolchinsky
end
end

07ad7166 Lucas Tolchinsky
test "when notification doesn't fails, if report has an error, no mail should be sent" do
SETTINGS[:failed_report_email_notification] = false
assert_no_difference 'ActionMailer::Base.deliveries.size' do
@report.status = 16781381 # Error status.
@report.save!
end
end

92ff1eef Lucas Tolchinsky
test "if report has no error, no mail should be sent" do
assert_no_difference 'ActionMailer::Base.deliveries.size' do
@report.status = 79
@report.save!
end
adb0dfd9 Ohad Levy
end
end