Project

General

Profile

« Previous | Next » 

Revision e8d6d2d6

Added by Shlomi Zadok over 8 years ago

fixes #4151 - enable reports STI

Permits subclassing of ReportImporter and Report to import and store
new types of reports associated to hosts.

View differences:

test/unit/report_importer_test.rb
end
test 'it should import reports with no metrics' do
r = ReportImporter.import(read_json_fixture('report-empty.json'))
r = TestReportImporter.import(read_json_fixture('report-empty.json'))
assert r
assert_equal({}, r.metrics)
end
......
@host = FactoryGirl.create(:host, :owner => @owner)
end
# Only ConfigReportImporter is set to send puppet error states
test 'when owner is subscribed to notification, a mail should be sent on error' do
@owner.mail_notifications << MailNotification[:puppet_error_state]
assert_difference 'ActionMailer::Base.deliveries.size' do
report = read_json_fixture('report-errors.json')
report["host"] = @host.name
ReportImporter.import report
ConfigReportImporter.import report
end
end
......
assert_no_difference 'ActionMailer::Base.deliveries.size' do
report = read_json_fixture('report-errors.json')
report["host"] = @host.name
ReportImporter.import report
TestReportImporter.import report
end
end
end
......
report = read_json_fixture('report-errors.json')
report["host"] = host.name
assert_no_difference 'ActionMailer::Base.deliveries.size' do
ReportImporter.import report
TestReportImporter.import report
end
end
# Only ConfigReportImporter is set to send puppet error states
test 'when usergroup owner is subscribed to notification, a mail should be sent to all users on error' do
ug = FactoryGirl.create(:usergroup, :users => FactoryGirl.create_pair(:user, :with_mail))
Usergroup.any_instance.expects(:recipients_for).with(:puppet_error_state).returns(ug.users)
host = FactoryGirl.create(:host, :owner => ug)
report = read_json_fixture('report-errors.json')
report["host"] = host.name
ReportImporter.import report
ConfigReportImporter.import report
assert_equal ug.users.map { |u| u.mail }, ActionMailer::Base.deliveries.map { |d| d.to }.flatten
end
test 'if report has no error, no mail should be sent' do
assert_no_difference 'ActionMailer::Base.deliveries.size' do
ReportImporter.import read_json_fixture('report-applied.json')
TestReportImporter.import read_json_fixture('report-applied.json')
end
end
......
assert_equal host, db_host
end
end
class TestReportImporter < ReportImporter
def report_status
0
end
end

Also available in: Unified diff