Project

General

Profile

« Previous | Next » 

Revision b1ac29e9

Added by Lukas Zapletal about 6 years ago

Fixes #23379 - proxy stubs on API level

View differences:

test/controllers/api/v2/config_reports_controller_test.rb
Setting[:restrict_registered_smart_proxies] = true
Setting[:require_ssl_smart_proxies] = false
ProxyAPI::Features.any_instance.stubs(:features => Feature.name_map.keys)
proxy = smart_proxies(:puppetmaster)
proxy.stubs(:associate_features)
as_admin { proxy.update_attribute(:url, 'http://configreports.foreman') }
host = URI.parse(proxy.url).host
Resolv.any_instance.stubs(:getnames).returns([host])
test/controllers/api/v2/hosts_controller_test.rb
end
test 'hosts with a registered smart proxy on should import facts successfully' do
ProxyAPI::Features.any_instance.stubs(:features => Feature.name_map.keys)
proxy = smart_proxies(:puppetmaster)
proxy.stubs(:associate_features)
proxy.update_attribute(:url, 'https://factsimporter.foreman')
User.current = users(:one) # use an unprivileged user, not apiadmin
test/controllers/api/v2/reports_controller_test.rb
Setting[:restrict_registered_smart_proxies] = true
Setting[:require_ssl_smart_proxies] = false
ProxyAPI::Features.any_instance.stubs(:features => Feature.name_map.keys)
proxy = smart_proxies(:puppetmaster)
proxy.stubs(:associate_features)
as_admin { proxy.update_attribute(:url, 'http://configreports.foreman') }
host = URI.parse(proxy.url).host
Resolv.any_instance.stubs(:getnames).returns([host])
test/controllers/api/v2/smart_proxies_controller_test.rb
test "should refresh smart proxy features" do
proxy = smart_proxies(:one)
SmartProxy.any_instance.stubs(:associate_features).returns(true)
post :refresh, params: { :id => proxy }
assert_response :success
response = ActiveSupport::JSON.decode(@response.body)
assert_equal [{'name' => 'DHCP', 'id' => features(:dhcp).id}], response['features']
assert_equal Feature.all.pluck(:name).flatten.sort, response['features'].map{|x| x['name']}.sort
end
test "should return errors during smart proxy refresh" do
......
errors = ActiveModel::Errors.new(Host::Managed.new)
errors.add :base, "Unable to communicate with the proxy: it's down"
SmartProxy.any_instance.stubs(:errors).returns(errors)
SmartProxy.any_instance.stubs(:associate_features).returns(true)
post :refresh, params: { :id => proxy }, session: set_session_user
assert_response :unprocessable_entity
end
test/controllers/smart_proxies_controller_test.rb
basic_pagination_per_page_test
setup do
SmartProxy.any_instance.stubs(:associate_features).returns(true)
ProxyAPI::Features.any_instance.stubs(:features => Feature.name_map.keys)
end
def test_index
......
end
def test_create_valid
ProxyAPI::Features.any_instance.stubs(:features => Feature.name_map.keys)
SmartProxy.any_instance.stubs(:valid?).returns(true)
SmartProxy.any_instance.stubs(:to_s).returns("puppet")
post :create, params: { :smart_proxy => {:name => "MySmartProxy", :url => "http://nowhere.net:8000"} }, session: set_session_user
......
def test_refresh
proxy = smart_proxies(:one)
SmartProxy.any_instance.stubs(:associate_features).returns(true)
SmartProxy.any_instance.stubs(:features).returns([features(:dns)])
post :refresh, params: { :id => proxy }, session: set_session_user
assert_redirected_to smart_proxies_url
assert_equal "No changes found when refreshing features from DHCP Proxy.", flash[:success]
......
def test_refresh_change
proxy = smart_proxies(:one)
SmartProxy.any_instance.stubs(:associate_features).returns(true)
SmartProxy.any_instance.stubs(:features).returns([features(:dns)]).then.returns([features(:dns), features(:tftp)])
post :refresh, params: { :id => proxy }, session: set_session_user
assert_redirected_to smart_proxies_url
......
errors = ActiveModel::Errors.new(Host::Managed.new)
errors.add :base, "Unable to communicate with the proxy: it is down"
SmartProxy.any_instance.stubs(:errors).returns(errors)
SmartProxy.any_instance.stubs(:associate_features).returns(true)
post :refresh, params: { :id => proxy }, session: set_session_user
assert_redirected_to smart_proxies_url
assert_equal "Unable to communicate with the proxy: it is down", flash[:error]
test/integration/smart_proxy_test.rb
class SmartProxyIntegrationTest < ActionDispatch::IntegrationTest
setup do
ProxyStatus::Version.any_instance.stubs(:version).returns({'version' => '1.11', 'modules' => {'dhcp' => '1.11'}})
SmartProxy.any_instance.stubs(:associate_features).returns(true)
ProxyAPI::Features.any_instance.stubs(:features => Feature.name_map.keys)
end
test "index page" do

Also available in: Unified diff