Sha256: 8fcb3e21fec66c943f5f9853faf1d11d01e620f7758aab30c44c17f2ffb4567d

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

require 'test_plugin_helper'

class ArfReportsControllerTest < ActionController::TestCase
  setup do
    ForemanOpenscap::Helper.stubs(:find_name_or_uuid_by_host)
    ::ProxyAPI::Openscap.any_instance.stubs(:destroy_report).returns(true)
    @host = FactoryBot.create(:compliance_host)
  end

  test "should delete arf report" do
    ForemanOpenscap::ArfReport.any_instance.stubs(:openscap_proxy).returns(@host.openscap_proxy)
    arf_report = FactoryBot.create(:arf_report, :host_id => @host.id)
    assert_difference("ForemanOpenscap::ArfReport.count", -1) do
      delete :destroy, { :id => arf_report.id }, set_session_user
    end
    assert_redirected_to arf_reports_path
  end

  test "should delete multiple reports" do
    ForemanOpenscap::ArfReport.any_instance.stubs(:openscap_proxy).returns(@host.openscap_proxy)
    arf_reports = []
    3.times do
      arf_reports << FactoryBot.create(:arf_report, :host_id => @host.id)
    end
    last_arf = arf_reports[-1]
    assert_difference("ForemanOpenscap::ArfReport.unscoped.count", -2) do
      post :submit_delete_multiple, { :arf_report_ids => arf_reports[0..-2].map(&:id) }, set_session_user
    end
    assert_redirected_to arf_reports_path
    assert_equal last_arf, ForemanOpenscap::ArfReport.unscoped.first
  end

  test "should download arf report as html" do
    arf_report = FactoryBot.create(:arf_report, :host_id => @host.id)
    report_html = File.read("#{ForemanOpenscap::Engine.root}/test/files/arf_report/arf_report.html")
    ForemanOpenscap::ArfReport.any_instance.stubs(:to_html).returns(report_html)
    get :download_html, { :id => arf_report.id }, set_session_user
    assert_equal report_html, @response.body
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_openscap-0.8.6 test/functional/arf_reports_controller_test.rb
foreman_openscap-0.8.5 test/functional/arf_reports_controller_test.rb
foreman_openscap-0.8.4 test/functional/arf_reports_controller_test.rb