Project

General

Profile

Download (2.81 KB) Statistics
| Branch: | Tag: | Revision:
958d69cd Dmitri Dolguikh
require 'test_helper'

class Api::V2::ConfigTemplatesControllerTest < ActionController::TestCase

test "should get index" do
get :index
templates = ActiveSupport::JSON.decode(@response.body)
assert !templates.empty?, "Should response with template"
assert_response :success
end

test "should get template detail" do
93ce3a18 Joseph Mitchell Magen
get :show, { :id => config_templates(:pxekickstart).to_param }
958d69cd Dmitri Dolguikh
assert_response :success
template = ActiveSupport::JSON.decode(@response.body)
assert !template.empty?
15d91324 Joseph Magen
assert_equal template["name"], config_templates(:pxekickstart).name
958d69cd Dmitri Dolguikh
end

test "should not create invalid" do
post :create
assert_response 422
end

test "should create valid" do
ConfigTemplate.any_instance.stubs(:valid?).returns(true)
0fa5d146 Dominic Cleal
valid_attrs = { :template => "This is a test template", :template_kind_id => template_kinds(:ipxe).id, :name => "RandomName" }
958d69cd Dmitri Dolguikh
post :create, { :config_template => valid_attrs }
template = ActiveSupport::JSON.decode(@response.body)
15d91324 Joseph Magen
assert template["name"] == "RandomName"
958d69cd Dmitri Dolguikh
assert_response 200
end

test "should not update invalid" do
93ce3a18 Joseph Mitchell Magen
put :update, { :id => config_templates(:pxekickstart).to_param,
958d69cd Dmitri Dolguikh
:config_template => { :name => "" } }
assert_response 422
end

test "should update valid" do
ConfigTemplate.any_instance.stubs(:valid?).returns(true)
93ce3a18 Joseph Mitchell Magen
put :update, { :id => config_templates(:pxekickstart).to_param,
958d69cd Dmitri Dolguikh
:config_template => { :template => "blah" } }
template = ActiveSupport::JSON.decode(@response.body)
assert_response :ok
end

test "should not destroy template with associated hosts" do
93ce3a18 Joseph Mitchell Magen
config_template = config_templates(:pxekickstart)
958d69cd Dmitri Dolguikh
delete :destroy, { :id => config_template.to_param }
assert_response 422
assert ConfigTemplate.exists?(config_template.id)
end

test "should destroy" do
93ce3a18 Joseph Mitchell Magen
config_template = config_templates(:pxekickstart)
958d69cd Dmitri Dolguikh
config_template.os_default_templates.clear
delete :destroy, { :id => config_template.to_param }
template = ActiveSupport::JSON.decode(@response.body)
assert_response :ok
assert !ConfigTemplate.exists?(config_template.id)
end

test "should build pxe menu" do
ProxyAPI::TFTP.any_instance.stubs(:create_default).returns(true)
ProxyAPI::TFTP.any_instance.stubs(:fetch_boot_file).returns(true)
get :build_pxe_default
assert_response 200
end

test "should add audit comment" do
ConfigTemplate.auditing_enabled = true
ConfigTemplate.any_instance.stubs(:valid?).returns(true)
93ce3a18 Joseph Mitchell Magen
put :update, { :id => config_templates(:pxekickstart).to_param,
958d69cd Dmitri Dolguikh
:config_template => { :audit_comment => "aha", :template => "tmp" } }
assert_response :success
93ce3a18 Joseph Mitchell Magen
assert_equal "aha", config_templates(:pxekickstart).audits.last.comment
958d69cd Dmitri Dolguikh
end
end