Sha256: dd5d256034d6720ef6271b64c52014d8119b6feecbde2aab2020242a934c63e3

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

require 'test_plugin_helper'

class Api::V2::Compliance::ScapContentsControllerTest < ActionController::TestCase
  test "should get index" do
    FactoryBot.create(:scap_content)
    get :index, {}, set_session_user
    response = ActiveSupport::JSON.decode(@response.body)
    assert response['results'].any?
    assert_response :success
  end

  test "should return xml of scap content" do
    scap_content = FactoryBot.create(:scap_content)
    get :show, { :id => scap_content.id }, set_session_user
    assert(@response.header['Content-Type'], 'application/xml')
    assert_response :success
  end

  test "should not create invalid scap content" do
    post :create, {}, set_session_user
    assert_response :unprocessable_entity
  end

  test "should create scap content" do
    # Skipped as API does not support uploading files
  end

  test "should update scap content" do
    scap_content = FactoryBot.create(:scap_content)
    put :update, { :id => scap_content.id, :scap_content => { :title => 'RHEL7 SCAP' } }, set_session_user
    assert_response :success
    assert scap_content.title, 'RHEL7 SCAP'
  end

  test "should not update invalid scap content" do
    skip("Solve 'ActiveRecord::RecordInvalid' error")
    ProxyAPI::Openscap.any_instance.stubs(:validate_scap_content).returns({ 'errors' => ['Invalid file'] })
    scap_content = FactoryBot.create(:scap_content)
    put :update, { :id => scap_content.id, :scap_content => { :scap_file => '<xml>blah</xml>' } }, set_session_user
    assert_response :unprocessable_entity
  end

  test "should destory scap content" do
    scap_content = FactoryBot.create(:scap_content)
    delete :destroy, { :id => scap_content.id }, set_session_user
    assert_response :ok
    refute ForemanOpenscap::ScapContent.exists?(scap_content.id)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_openscap-0.8.6 test/functional/api/v2/compliance/scap_contents_controller_test.rb
foreman_openscap-0.8.5 test/functional/api/v2/compliance/scap_contents_controller_test.rb
foreman_openscap-0.8.4 test/functional/api/v2/compliance/scap_contents_controller_test.rb