Skip to content

Commit 33ddacc

Browse files
authored
Merge pull request #13 from witlessbird/internal-api-test
Added internal api tests
2 parents 3fa702a + be990ae commit 33ddacc

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@ source 'https://rubygems.org'
22
gemspec
33

44
group :development do
5+
if RUBY_VERSION < '2.2.2'
6+
gem 'rack-test', '~> 0.7.0'
7+
else
8+
gem 'rack-test'
9+
end
10+
511
gem 'smart_proxy', :git => 'https://github.com/theforeman/smart-proxy.git', :branch => 'develop'
612
end

test/internal_api_test.rb

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)