|
| 1 | +require 'test_helper' |
| 2 | +require 'rack/test' |
| 3 | +require 'realm/configuration_loader' |
| 4 | +require 'smart_proxy_realm_ad_plugin' |
| 5 | +require 'smart_proxy_realm_ad/provider' |
| 6 | + |
| 7 | +ENV['RACK_ENV'] = 'test' |
| 8 | + |
| 9 | +module Proxy::Realm |
| 10 | + module DependencyInjection |
| 11 | + include Proxy::DependencyInjection::Accessors |
| 12 | + def container_instance; end |
| 13 | + end |
| 14 | +end |
| 15 | + |
| 16 | +require 'realm/realm_api' |
| 17 | + |
| 18 | +class InternalApiTest < Test::Unit::TestCase |
| 19 | + include Rack::Test::Methods |
| 20 | + |
| 21 | + def app |
| 22 | + app = Proxy::Realm::Api.new |
| 23 | + app.helpers.realm_provider = @server |
| 24 | + app |
| 25 | + end |
| 26 | + |
| 27 | + def setup |
| 28 | + @server = Proxy::AdRealm::Provider.new(:realm => "test.com") |
| 29 | + end |
| 30 | + |
| 31 | + def test_create_host |
| 32 | + realm = "TEST.COM" |
| 33 | + hostname = "test.com" |
| 34 | + @server.expects(:create).with(realm, hostname, is_a(Hash)) |
| 35 | + post "/#{realm}", :hostname => 'test.com' |
| 36 | + assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}" |
| 37 | + end |
| 38 | + |
| 39 | + def test_rebuild_host |
| 40 | + realm = "TEST.COM" |
| 41 | + hostname = "test.com" |
| 42 | + @server.expects(:create).with(realm, hostname, has_entry('rebuild', 'true')) |
| 43 | + post "/#{realm}", :hostname => 'test.com', :rebuild => true |
| 44 | + assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}" |
| 45 | + end |
| 46 | + |
| 47 | + def test_delete_host |
| 48 | + realm = "TEST.COM" |
| 49 | + hostname = "test.com" |
| 50 | + @server.expects(:delete).with(realm, hostname) |
| 51 | + delete "/#{realm}/#{hostname}" |
| 52 | + assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}" |
| 53 | + end |
| 54 | +end |
0 commit comments