deltacloud-core 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,78 +0,0 @@
1
- require 'tests/common'
2
-
3
- module DeltacloudUnitTest
4
- class RealmsTest < Test::Unit::TestCase
5
- include Rack::Test::Methods
6
-
7
- def app
8
- Sinatra::Application
9
- end
10
-
11
- def test_it_not_require_authentication
12
- require_authentication?('/api/realms').should_not == true
13
- end
14
-
15
- def test_it_returns_realms
16
- do_xml_request '/api/realms', {}, true
17
- (last_xml_response/'realms/realm').map.size.should > 0
18
- end
19
-
20
- def test_it_has_correct_attributes_set
21
- do_xml_request '/api/realms', {}, true
22
- (last_xml_response/'realms/realm').each do |realm|
23
- realm.attributes.keys.sort.should == [ 'href', 'id' ]
24
- end
25
- end
26
-
27
- def test_us_has_correct_attributes
28
- do_xml_request '/api/realms', {}, true
29
- realm = (last_xml_response/'realms/realm[@id="us"]')
30
- test_realm_attributes(realm)
31
- end
32
-
33
- def test_it_returns_valid_realm
34
- do_xml_request '/api/realms/us', {}, true
35
- realm = (last_xml_response/'realm')
36
- test_realm_attributes(realm)
37
- end
38
-
39
- def test_it_has_unique_ids
40
- do_xml_request '/api/realms', {}, true
41
- ids = []
42
- (last_xml_response/'realms/realm').each do |realm|
43
- ids << realm['id'].to_s
44
- end
45
- ids.sort.should == ids.sort.uniq
46
- end
47
-
48
- def test_it_responses_to_json
49
- do_request '/api/realms', {}, false, { :format => :json }
50
- JSON::parse(last_response.body).class.should == Hash
51
- JSON::parse(last_response.body)['realms'].class.should == Array
52
-
53
- do_request '/api/realms/us', {}, false, { :format => :json }
54
- last_response.status.should == 200
55
- JSON::parse(last_response.body).class.should == Hash
56
- JSON::parse(last_response.body)['realm'].class.should == Hash
57
- end
58
-
59
- def test_it_responses_to_html
60
- do_request '/api/realms', {}, false, { :format => :html }
61
- last_response.status.should == 200
62
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
63
-
64
- do_request '/api/realms/us', {}, false, { :format => :html }
65
- last_response.status.should == 200
66
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
67
- end
68
-
69
- private
70
-
71
- def test_realm_attributes(realm)
72
- (realm/'name').should_not == nil
73
- (realm/'limit').should_not == nil
74
- ['AVAILABLE'].include?((realm/'state').text).should == true
75
- end
76
-
77
- end
78
- end
@@ -1,50 +0,0 @@
1
- require 'tests/common'
2
-
3
- module DeltacloudUnitTest
4
- class UrlForTest < Test::Unit::TestCase
5
- include Rack::Test::Methods
6
-
7
- def app
8
- Sinatra::Application
9
- end
10
-
11
- def test_it_works_for_root
12
- verify_url_for("/", "/")
13
- end
14
-
15
- def test_it_works_for_root_absolute
16
- verify_url_for("/", "http://localhost/", :full)
17
- end
18
-
19
- def test_it_works_with_spaces
20
- verify_url_for("/url with spaces", "/url%20with%20spaces")
21
- end
22
-
23
- def test_it_works_when_given_absolute
24
- verify_url_for("http://test.com", "http://test.com")
25
- end
26
-
27
- def test_it_works_when_not_at_root_context
28
- verify_url_for("/", "context/", :path_only, {}, {"SCRIPT_NAME" => "context"})
29
- end
30
-
31
- def verify_url_for(url, expected_url, mode=:path_only, params={}, rack_env={})
32
- # generate a unique url for each test
33
- test_url = "/url_for_test/#{expected_url.hash}/#{Time.now.to_i}"
34
- # Create our sinatra test endpoint
35
- self.class.create_test_url_content(test_url, url, mode)
36
-
37
- # verify the generated url matches what we expect
38
- get test_url, params, rack_env
39
- last_response.body.should == expected_url
40
- end
41
-
42
- def self.create_test_url_content(test_url, url_content, mode)
43
- get test_url do
44
- content_type "text/plain"
45
- url_for(url_content, mode)
46
- end
47
- end
48
-
49
- end
50
- end