studio_api 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/README +93 -0
  2. data/Rakefile +64 -0
  3. data/VERSION +1 -0
  4. data/lib/studio_api/appliance.rb +365 -0
  5. data/lib/studio_api/build.rb +17 -0
  6. data/lib/studio_api/connection.rb +102 -0
  7. data/lib/studio_api/file.rb +70 -0
  8. data/lib/studio_api/generic_request.rb +160 -0
  9. data/lib/studio_api/package.rb +12 -0
  10. data/lib/studio_api/pattern.rb +12 -0
  11. data/lib/studio_api/repository.rb +35 -0
  12. data/lib/studio_api/rpm.rb +33 -0
  13. data/lib/studio_api/running_build.rb +35 -0
  14. data/lib/studio_api/studio_resource.rb +70 -0
  15. data/lib/studio_api/template_set.rb +12 -0
  16. data/lib/studio_api/util.rb +38 -0
  17. data/lib/studio_api.rb +31 -0
  18. data/test/appliance_test.rb +189 -0
  19. data/test/build_test.rb +45 -0
  20. data/test/connection_test.rb +21 -0
  21. data/test/file_test.rb +52 -0
  22. data/test/generic_request_test.rb +66 -0
  23. data/test/repository_test.rb +42 -0
  24. data/test/resource_test.rb +49 -0
  25. data/test/responses/appliance.xml +27 -0
  26. data/test/responses/appliances.xml +199 -0
  27. data/test/responses/build.xml +17 -0
  28. data/test/responses/builds.xml +19 -0
  29. data/test/responses/file.xml +12 -0
  30. data/test/responses/files.xml +14 -0
  31. data/test/responses/gpg_key.xml +25 -0
  32. data/test/responses/gpg_keys.xml +77 -0
  33. data/test/responses/repositories.xml +42 -0
  34. data/test/responses/repository.xml +8 -0
  35. data/test/responses/rpm.xml +10 -0
  36. data/test/responses/rpms.xml +404 -0
  37. data/test/responses/running_build.xml +7 -0
  38. data/test/responses/running_builds.xml +23 -0
  39. data/test/responses/software.xml +50 -0
  40. data/test/responses/software_installed.xml +729 -0
  41. data/test/responses/software_search.xml +64 -0
  42. data/test/responses/status-broken.xml +9 -0
  43. data/test/responses/status.xml +4 -0
  44. data/test/responses/template_sets.xml +380 -0
  45. data/test/rpm_test.rb +59 -0
  46. data/test/running_build_test.rb +50 -0
  47. data/test/template_set_test.rb +35 -0
  48. metadata +181 -0
@@ -0,0 +1,189 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ $:.unshift File.join( File.dirname(__FILE__),'..','lib')
4
+ require 'studio_api/appliance'
5
+ require 'studio_api/connection'
6
+ require 'studio_api/generic_request'
7
+ require 'studio_api/util'
8
+ require 'active_resource/http_mock'
9
+ require 'mocha'
10
+ require 'test/unit'
11
+
12
+ class ApplianceTest < Test::Unit::TestCase
13
+ APPLIANCE_ID = 266657
14
+ REPO_ID = 6345
15
+ def respond_load name
16
+ IO.read(File.join(File.dirname(__FILE__),"responses",name))
17
+ end
18
+
19
+ def setup
20
+ @connection = StudioApi::Connection.new("test","test","http://localhost/api/")
21
+ StudioApi::Util.configure_studio_connection @connection
22
+ appliances_out = respond_load "appliances.xml"
23
+ appliance_out = respond_load "appliance.xml"
24
+ status_out = respond_load "status.xml"
25
+ repositories_out = respond_load "repositories.xml"
26
+ gpg_keys_out = respond_load "gpg_keys.xml"
27
+ gpg_key_out = respond_load "gpg_key.xml"
28
+ ActiveResource::HttpMock.respond_to do |mock|
29
+ mock.get "/api/appliances", {"Authorization"=>"Basic dGVzdDp0ZXN0"},appliances_out,200
30
+ mock.get "/api/appliances/#{APPLIANCE_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"},appliance_out,200
31
+ mock.get "/api/appliances/#{APPLIANCE_ID}/status", {"Authorization"=>"Basic dGVzdDp0ZXN0"},status_out,200
32
+ mock.delete "/api/appliances/#{APPLIANCE_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"},appliance_out,200
33
+ mock.get "/api/appliances/#{APPLIANCE_ID}/repositories", {"Authorization"=>"Basic dGVzdDp0ZXN0"},repositories_out,200
34
+ mock.post "/api/appliances/#{APPLIANCE_ID}/cmd/add_repository?repo_id=#{REPO_ID}",{"Authorization"=>"Basic dGVzdDp0ZXN0"},repositories_out,200
35
+ mock.post "/api/appliances/#{APPLIANCE_ID}/cmd/add_user_repository",{"Authorization"=>"Basic dGVzdDp0ZXN0"},repositories_out,200
36
+ mock.get "/api/appliances/#{APPLIANCE_ID}/gpg_keys", {"Authorization"=>"Basic dGVzdDp0ZXN0"},gpg_keys_out,200
37
+ mock.get "/api/appliances/#{APPLIANCE_ID}/gpg_keys/1976", {"Authorization"=>"Basic dGVzdDp0ZXN0"},gpg_key_out,200
38
+ mock.delete "/api/appliances/#{APPLIANCE_ID}/gpg_keys/1976", {"Authorization"=>"Basic dGVzdDp0ZXN0"},gpg_key_out,200
39
+ end
40
+ end
41
+
42
+ def teardown
43
+ Mocha::Mockery.instance.stubba.unstub_all
44
+ end
45
+
46
+ def test_find_all
47
+ res = StudioApi::Appliance.find :all
48
+ assert_equal 7,res.size
49
+ end
50
+
51
+ def test_find_one
52
+ res = StudioApi::Appliance.find APPLIANCE_ID
53
+ assert_equal APPLIANCE_ID.to_s, res.id
54
+ end
55
+
56
+ def test_status
57
+ res = StudioApi::Appliance.find APPLIANCE_ID
58
+ assert_equal "ok", res.status.state
59
+ end
60
+
61
+ def test_maintenance_status
62
+ status_out = respond_load "status-broken.xml"
63
+ ActiveResource::HttpMock.respond_to do |mock|
64
+ mock.get "/api/appliances/#{APPLIANCE_ID}/status", {"Authorization"=>"Basic dGVzdDp0ZXN0"},status_out,200
65
+ end
66
+ res = StudioApi::Appliance.new(:id => APPLIANCE_ID)
67
+ assert_equal "error", res.status.state
68
+ end
69
+
70
+ def test_clone
71
+ appliance_out = respond_load "appliance.xml"
72
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances?clone_from=#{APPLIANCE_ID}",{}).returns(appliance_out).once
73
+ assert StudioApi::Appliance.clone APPLIANCE_ID
74
+ end
75
+
76
+ def test_delete
77
+ assert StudioApi::Appliance.delete APPLIANCE_ID
78
+ assert StudioApi::Appliance.find(APPLIANCE_ID).destroy #same but different way
79
+ end
80
+
81
+ def test_repositories
82
+ res = StudioApi::Appliance.new(:id => APPLIANCE_ID).repositories
83
+ assert_equal 5,res.size
84
+ end
85
+
86
+ def test_repository_remove
87
+ repositories_out = respond_load "repositories.xml"
88
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/remove_repository?repo_id=#{REPO_ID}").returns(repositories_out)
89
+ appliance = StudioApi::Appliance.new(:id => APPLIANCE_ID)
90
+ assert appliance.remove_repository REPO_ID
91
+ repo = appliance.repositories.detect { |r| r.id == REPO_ID.to_s}
92
+ assert repo.destroy #another way to delete repository
93
+ end
94
+
95
+ def test_repository_add
96
+ repositories_out = respond_load "repositories.xml"
97
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/add_repository?repo_id=#{REPO_ID}").returns(repositories_out)
98
+ assert StudioApi::Appliance.new(:id => APPLIANCE_ID).add_repository REPO_ID
99
+ end
100
+
101
+ def test_user_repository_add
102
+ repositories_out = respond_load "repositories.xml"
103
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/add_user_repository").returns(repositories_out)
104
+ assert StudioApi::Appliance.new(:id => APPLIANCE_ID).add_user_repository
105
+ end
106
+
107
+ def test_selected_software
108
+ software_out = respond_load "software.xml"
109
+ StudioApi::GenericRequest.any_instance.stubs(:get).with("/appliances/#{APPLIANCE_ID}/software").returns(software_out).once
110
+ res = StudioApi::Appliance.new(:id => APPLIANCE_ID).selected_software
111
+ assert_equal 48,res.size
112
+ assert res.any? {|r| r.is_a? StudioApi::Pattern }, "Pattern is not loaded"
113
+ assert res.any? {|r| r.name = "sysvinit" && r.version == "2.86-200.1" }, "package with specified version not found"
114
+ end
115
+
116
+ def test_installed_software
117
+ software_in_out = respond_load "software_installed.xml"
118
+ StudioApi::GenericRequest.any_instance.stubs(:get).with("/appliances/#{APPLIANCE_ID}/software/installed?build_id=1").returns(software_in_out).once
119
+ res = StudioApi::Appliance.new(:id => APPLIANCE_ID).installed_software :build_id => 1
120
+ assert_equal 608,res.size
121
+ assert res.any? {|r| r.is_a? StudioApi::Pattern }, "Pattern is not loaded"
122
+ diag = res.find { |p| p.name == "3ddiag"}
123
+ assert_equal "0.742-32.25",diag.version
124
+ assert_equal 6347,diag.repository_id
125
+ end
126
+
127
+ def test_search_software
128
+ software_se_out = respond_load "software_search.xml"
129
+ StudioApi::GenericRequest.any_instance.stubs(:get).with("/appliances/#{APPLIANCE_ID}/software/search?q=qt").returns(software_se_out).once
130
+ res = StudioApi::Appliance.new(:id => APPLIANCE_ID).search_software "qt"
131
+ assert_equal 54,res.size
132
+ assert res.any? {|r| r.is_a? StudioApi::Pattern }, "Pattern is not loaded"
133
+ apport = res.find { |p| p.name == "apport-qt"}
134
+ assert_equal "0.114-12.7.10",apport.version
135
+ assert_equal 6347,apport.repository_id
136
+ end
137
+
138
+ SOFTWARE_FAKE_RESPONSE= <<EOF
139
+ <success>
140
+ <details>
141
+ <status>
142
+ <state>changed</state>
143
+ <packages_added>13</packages_added>
144
+ <packages_removed>0</packages_removed>
145
+ </status>
146
+ </details>
147
+ </success>
148
+ EOF
149
+ def test_manipulate_with_packages_and_pattern
150
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/add_package?name=3ddiag",:name => "3ddiag").returns(SOFTWARE_FAKE_RESPONSE).once
151
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/remove_package?name=3ddiag",:name => "3ddiag").returns(SOFTWARE_FAKE_RESPONSE).once
152
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/add_pattern?name=kde4", :name => "kde4").returns(SOFTWARE_FAKE_RESPONSE).once
153
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/remove_pattern?name=kde4",:name => "kde4").returns(SOFTWARE_FAKE_RESPONSE).once
154
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/ban_package?name=3ddiag",:name => "3ddiag").returns(SOFTWARE_FAKE_RESPONSE).once
155
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/unban_package?name=3ddiag",:name => "3ddiag").returns(SOFTWARE_FAKE_RESPONSE).once
156
+ appliance = StudioApi::Appliance.new(:id => APPLIANCE_ID)
157
+ assert appliance.add_package "3ddiag"
158
+ assert appliance.remove_package "3ddiag"
159
+ assert appliance.add_pattern "kde4"
160
+ assert appliance.remove_pattern "kde4"
161
+ assert appliance.ban_package "3ddiag"
162
+ assert appliance.unban_package "3ddiag"
163
+ end
164
+
165
+ def test_gpg_keys
166
+ res = StudioApi::Appliance.new(:id => APPLIANCE_ID).gpg_keys
167
+ assert_equal 3,res.size
168
+ end
169
+
170
+ def test_gpg_key
171
+ res = StudioApi::Appliance.new(:id => APPLIANCE_ID).gpg_key 1976
172
+ assert_equal 1976, res.id.to_i
173
+ assert_equal "rpm", res.target
174
+ end
175
+
176
+ def test_delete_gpg_key
177
+ assert StudioApi::Appliance::GpgKey.delete 1976, :appliance_id => APPLIANCE_ID
178
+ res = StudioApi::Appliance.new(:id => APPLIANCE_ID).gpg_key 1976
179
+ assert res.destroy
180
+ end
181
+
182
+ def test_add_gpg_key
183
+ gpg_key_out = respond_load "gpg_key.xml"
184
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/gpg_keys?name=test&target=rpm&key=test",nil).returns(gpg_key_out)
185
+ StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/gpg_keys?name=test&key=test&target=rpm",nil).returns(gpg_key_out)
186
+ assert StudioApi::Appliance::GpgKey.create APPLIANCE_ID, "test", "test"
187
+ assert StudioApi::Appliance.new(:id => APPLIANCE_ID).add_gpg_key "test", "test"
188
+ end
189
+ end
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_resource/http_mock'
4
+ require 'mocha'
5
+ require 'test/unit'
6
+ $:.unshift File.join( File.dirname(__FILE__), '..', 'lib')
7
+ require 'studio_api/build'
8
+ require 'studio_api/connection'
9
+
10
+ class BuildTest < Test::Unit::TestCase
11
+ BUILD_ID = 509559
12
+ APPLIANCE_ID = 269186
13
+
14
+ def respond_load name
15
+ IO.read(File.join(File.dirname(__FILE__), "responses", name))
16
+ end
17
+
18
+ def setup
19
+ @connection = StudioApi::Connection.new("test", "test", "http://localhost")
20
+ StudioApi::Build.studio_connection = @connection
21
+
22
+ builds_out = respond_load "builds.xml"
23
+ build_out = respond_load "build.xml"
24
+
25
+ ActiveResource::HttpMock.respond_to do |mock|
26
+ mock.get "/builds?appliance_id=#{APPLIANCE_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"}, builds_out, 200
27
+ mock.get "/builds/#{BUILD_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"}, build_out, 200
28
+ mock.delete "/builds/#{BUILD_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"}, build_out, 200
29
+ end
30
+ end
31
+
32
+ def test_find
33
+ res = StudioApi::Build.find :all, :params => {:appliance_id => APPLIANCE_ID}
34
+ assert_equal 1, res.size
35
+ res = StudioApi::Build.find BUILD_ID
36
+ assert_equal "true", res.expired
37
+ end
38
+
39
+ def test_delete
40
+ build = StudioApi::Build.find BUILD_ID
41
+ assert build.destroy
42
+ assert StudioApi::Build.delete BUILD_ID
43
+ end
44
+
45
+ end
@@ -0,0 +1,21 @@
1
+ require "rubygems"
2
+ $:.unshift File.join( File.dirname(__FILE__),'..','lib')
3
+ require 'studio_api/connection'
4
+ require 'studio_api/generic_request'
5
+
6
+ require 'mocha'
7
+ require 'test/unit'
8
+
9
+ class ConnectionTest < Test::Unit::TestCase
10
+ def setup
11
+ @connection = StudioApi::Connection.new("test","test","http://localhost/api/user")
12
+ end
13
+
14
+ FAKE_API_VERSION_RESPONSE = "<version>1.0</version>"
15
+ def test_api_version
16
+ StudioApi::GenericRequest.any_instance.stubs(:get).with("/api_version").returns(FAKE_API_VERSION_RESPONSE).once
17
+ assert_equal "1.0",@connection.api_version
18
+ @connection.api_version #test caching, if it again call, then mocha raise exception
19
+ end
20
+
21
+ end
data/test/file_test.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ $:.unshift File.join( File.dirname(__FILE__),'..','lib')
4
+ require 'studio_api/file'
5
+ require 'studio_api/connection'
6
+
7
+ require 'active_resource/http_mock'
8
+ require 'mocha'
9
+ require 'test/unit'
10
+
11
+ #FileTest cause collistion of names
12
+ class File1Test < Test::Unit::TestCase
13
+ APPLIANCE_ID=488
14
+ FILE_ID = 1234765
15
+
16
+ def respond_load name
17
+ IO.read(File.join(File.dirname(__FILE__),"responses",name))
18
+ end
19
+
20
+ def setup
21
+ @connection = StudioApi::Connection.new("test","test","http://localhost")
22
+ StudioApi::File.studio_connection = @connection
23
+ files_out = respond_load "files.xml"
24
+ file_out = respond_load "file.xml"
25
+ ActiveResource::HttpMock.respond_to do |mock|
26
+ mock.get "/files?appliance_id=#{APPLIANCE_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"},files_out,200
27
+ mock.get "/files/#{FILE_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"},file_out,200
28
+ mock.delete "/files/#{FILE_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"},file_out,200
29
+ mock.put "/files/#{FILE_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"},file_out,200
30
+ end
31
+ end
32
+
33
+ def test_find
34
+ res = StudioApi::File.find :all, :params => { :appliance_id => APPLIANCE_ID }
35
+ assert_equal 1, res.size
36
+ assert_equal "http://susestudio.com/file/download/214486/1234765", res[0].download_url
37
+ res = StudioApi::File.find FILE_ID
38
+ assert_equal "http://susestudio.com/file/download/214486/1234765", res.download_url
39
+ end
40
+
41
+ def test_delete
42
+ assert StudioApi::File.find(FILE_ID).destroy
43
+ assert StudioApi::File.delete FILE_ID #different way
44
+ end
45
+
46
+ def test_update
47
+ f = StudioApi::File.find(FILE_ID)
48
+ f.path = "/tmp"
49
+ assert f.save
50
+ end
51
+ end
52
+
@@ -0,0 +1,66 @@
1
+ require 'rubygems'
2
+ require 'mocha'
3
+ require 'test/unit'
4
+ $:.unshift File.join( File.dirname(__FILE__),'..','lib')
5
+ require 'studio_api/generic_request'
6
+ require 'studio_api/connection'
7
+ require 'net/http'
8
+
9
+ class GenericRequestTest < Test::Unit::TestCase
10
+ def setup
11
+ Mocha::Mockery.instance.stubba.unstub_all
12
+ @connection = StudioApi::Connection.new("test","test","http://localhost")
13
+ end
14
+
15
+ def teardown
16
+ Mocha::Mockery.instance.stubba.unstub_all
17
+ end
18
+
19
+ ERROR_RESPONSE = <<EOF
20
+ <error>
21
+ <code>invalid_base_system</code>
22
+ <message>Invalid base system.</message>
23
+ </error>
24
+ EOF
25
+ def test_get
26
+ test_response = "Test response"
27
+ StudioApi::GenericRequest.any_instance.stubs(:do_request).returns test_response
28
+ assert_equal test_response, StudioApi::GenericRequest.new(@connection).get("test")
29
+ end
30
+
31
+ def test_post
32
+ test_response = "Test response"
33
+ StudioApi::GenericRequest.any_instance.stubs(:do_request).returns test_response
34
+ assert_equal test_response, StudioApi::GenericRequest.new(@connection).post("test",:file => "/dev/zero")
35
+ end
36
+
37
+ def test_error_response
38
+ response = Net::HTTPServiceUnavailable.new("4.1",503,"Unnavailable")
39
+ response.instance_variable_set "@body", ERROR_RESPONSE
40
+ response.instance_variable_set "@read", true #avoid real reading
41
+ Net::HTTP.any_instance.stubs(:request).returns(response)
42
+ rq = StudioApi::GenericRequest.new(@connection)
43
+ http_var = rq.instance_variable_get("@http")
44
+ def http_var.start
45
+ yield
46
+ end
47
+ assert_raises(ActiveResource::ServerError) { rq.get("test") }
48
+ end
49
+
50
+ def test_mime_type
51
+ request = StudioApi::GenericRequest.new @connection
52
+ assert_equal 'image/jpg', request.send(:mime_type, '/test/file.JPG')
53
+ assert_equal 'image/jpg', request.send(:mime_type, 'test.jpeg')
54
+ assert_equal 'image/gif', request.send(:mime_type, '/some_dir/some_file.GIF')
55
+ assert_equal 'image/png', request.send(:mime_type, '/use_this.png')
56
+ end
57
+
58
+ def test_ssl_settings
59
+ @connection = StudioApi::Connection.new("test","test","https://localhost",:ssl => { :verify_mode => OpenSSL::SSL::VERIFY_PEER, :ca_path => "/dev/null" })
60
+ rq = StudioApi::GenericRequest.new @connection
61
+ http_var = rq.instance_variable_get("@http")
62
+ assert http_var.use_ssl?
63
+ assert_equal OpenSSL::SSL::VERIFY_PEER, http_var.verify_mode
64
+ assert_equal "/dev/null", http_var.ca_path
65
+ end
66
+ end
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ $:.unshift File.join( File.dirname(__FILE__),'..','lib')
4
+ require 'studio_api/repository'
5
+ require 'studio_api/appliance'
6
+ require 'studio_api/connection'
7
+
8
+ require 'active_resource/http_mock'
9
+ require 'mocha'
10
+ require 'test/unit'
11
+
12
+ class RepositoryTest < Test::Unit::TestCase
13
+ REPOSITORY_ID = 6343
14
+ def respond_load name
15
+ IO.read(File.join(File.dirname(__FILE__),"responses",name))
16
+ end
17
+ def setup
18
+ @connection = StudioApi::Connection.new("test","test","http://localhost")
19
+ StudioApi::Repository.studio_connection = @connection
20
+ repositories_out = respond_load "repositories.xml"
21
+ repository_out = respond_load "repository.xml"
22
+ ActiveResource::HttpMock.respond_to do |mock|
23
+ mock.get "/repositories?base_system=sle11sp1", {"Authorization"=>"Basic dGVzdDp0ZXN0"},repositories_out,200
24
+ mock.post "/repositories?name=test&url=http%3A%2F%2Ftest", {"Authorization"=>"Basic dGVzdDp0ZXN0"},repository_out,200
25
+ mock.get "/repositories/#{REPOSITORY_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"},repository_out,200
26
+ end
27
+ end
28
+
29
+ def test_find
30
+ res = StudioApi::Repository.find :all, :params => {:base_system => "sle11sp1"}
31
+ assert_equal 5,res.size
32
+ res = StudioApi::Repository.find REPOSITORY_ID
33
+ assert_equal REPOSITORY_ID, res.id.to_i
34
+ end
35
+
36
+ def test_import
37
+ res = StudioApi::Repository.import "http://test","test"
38
+ assert res
39
+ assert_equal REPOSITORY_ID, res.id.to_i
40
+ end
41
+ end
42
+
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ $:.unshift File.join( File.dirname(__FILE__),'..','lib')
4
+ require 'studio_api/studio_resource'
5
+ require 'studio_api/connection'
6
+
7
+ require 'active_resource/http_mock'
8
+ require 'mocha'
9
+ require 'test/unit'
10
+
11
+ class MyTest < ActiveResource::Base
12
+ extend StudioApi::StudioResource
13
+ end
14
+
15
+ class MyTest2 < ActiveResource::Base
16
+ extend StudioApi::StudioResource
17
+ self.prefix = "/appliance/:test/"
18
+ end
19
+
20
+ class C < ActiveResource::Base
21
+ extend StudioApi::StudioResource
22
+ self.collection_name = "Cecka"
23
+ end
24
+
25
+ class ResourceTest < Test::Unit::TestCase
26
+ def setup
27
+ @connection = StudioApi::Connection.new("test","test","http://localhost/api/user")
28
+ MyTest.studio_connection = @connection
29
+ MyTest2.studio_connection = @connection
30
+ end
31
+
32
+ def test_site
33
+ assert_equal "/api/user/my_tests", MyTest.collection_path
34
+ assert_equal "http://localhost/api/user", MyTest.site.to_s
35
+ assert_equal "/api/user/appliance/lest/my_test2s", MyTest2.collection_path(:test => "lest")
36
+ end
37
+
38
+ def test_concurrent_connection
39
+ con1 = StudioApi::Connection.new("test","test","http://localhost/api/user")
40
+ con2 = StudioApi::Connection.new("test2","test2","http://localhost/api/user")
41
+ c1 = C.dup
42
+ c1.studio_connection = con1
43
+ c2 = C.dup
44
+ c2.studio_connection = con2
45
+ assert_equal "test",c1.studio_connection.user
46
+ assert_equal "test2",c2.studio_connection.user
47
+ end
48
+
49
+ end
@@ -0,0 +1,27 @@
1
+ <appliance>
2
+ <id>266657</id>
3
+ <name>josef's SLES 11 SP1 git test</name>
4
+ <arch>i586</arch>
5
+ <type>vmx</type>
6
+ <last_edited>2010-10-08 14:46:07 UTC</last_edited>
7
+ <estimated_raw_size>390 MB</estimated_raw_size>
8
+ <estimated_compressed_size>140 MB</estimated_compressed_size>
9
+ <edit_url>http://susestudio.com/appliance/edit/266657</edit_url>
10
+ <icon_url>http://susestudio.com/api/v1/user/appliance_icon/266657</icon_url>
11
+ <basesystem>SLES11_SP1</basesystem>
12
+ <uuid>b1e01a64-d2ea-11df-f1ab-475ae2f5345b</uuid>
13
+ <parent>
14
+ <id>202443</id>
15
+ <name>SLES 11 SP1, Just enough OS (JeOS)</name>
16
+ </parent>
17
+ <builds type="array">
18
+ <build>
19
+ <id>509559</id>
20
+ <version>0.0.1</version>
21
+ <image_type>vmx</image_type>
22
+ <image_size>695</image_size>
23
+ <compressed_image_size>121</compressed_image_size>
24
+ <download_url>http://susestudio.com/download/a0f0217f0645099c9e41c42e9bf89976/josefs_SLES_11_SP1_git_test.i686-0.0.1.vmx.tar.gz</download_url>
25
+ </build>
26
+ </builds>
27
+ </appliance>