studio_api 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg
2
+ doc
3
+
4
+ # Gemfile.lock should not be added to git
5
+ # For more details: http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
6
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'fakeweb'
7
+ gem 'mocha'
8
+ end
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'rake'
2
2
  require 'rake/rdoctask'
3
3
  require 'rake/testtask'
4
+ require 'bundler'
5
+
6
+ Bundler::GemHelper.install_tasks
4
7
 
5
8
  task :default => "test"
6
9
 
@@ -20,46 +23,3 @@ rescue LoadError
20
23
  puts "Yard not available. To generate documentation install it with: gem install yard"
21
24
  end
22
25
 
23
-
24
- begin
25
- require 'jeweler'
26
- Jeweler::Tasks.new do |s|
27
- s.name = %q{studio_api}
28
- s.summary = %q{Intuitive ruby bindings to Studio Api Interface.}
29
- s.description = %q{Studio Api makes it easier to use SuSE Studio (http://susestudio.com) via API.
30
- Instead of adapting each ActiveResource to its behavior and
31
- manually adding multipart file upload it wrapp in in Active
32
- Resource like interface. It is possible to define credentials
33
- for whole api, or use it per partes, so it allow using it for
34
- different studio users together.}
35
-
36
- s.files = FileList['[A-Z]*', 'lib/studio_api/*.rb','lib/studio_api.rb', 'test/**/*.rb']
37
- s.require_path = 'lib'
38
- s.test_files = Dir[*['test/*_test.rb','test/responses/*.xml']]
39
- s.has_rdoc = true
40
- s.extra_rdoc_files = ["README.rdoc"]
41
- s.rdoc_options = ['--line-numbers', "--main", "README.rdoc"]
42
- s.authors = ["Josef Reidinger"]
43
- s.email = %q{jreidinger@suse.cz}
44
- s.homepage = "http://github.com/jreidinger/studio_api"
45
- s.license = ["GPLv2","The Ruby License"]
46
- s.add_dependency "activeresource", ">= 2.3.8"
47
- s.add_dependency "xml-simple", ">= 1.0.0"
48
- s.platform = Gem::Platform::RUBY
49
- end
50
- Jeweler::GemcutterTasks.new
51
-
52
- desc "Create package directory containing all things to build RPM"
53
- task :package => [:build] do
54
- pkg_name = "rubygem-studio_api"
55
- include FileUtils::Verbose
56
- rm_rf "package"
57
- mkdir "package"
58
- cp "#{pkg_name}.changes","package/"
59
- cp "#{pkg_name}.spec.template","package/#{pkg_name}.spec"
60
- sh 'cp pkg/*.gem package/'
61
- sh "sed -i \"s:<VERSION>:`cat VERSION`:\" package/#{pkg_name}.spec"
62
- end
63
- rescue LoadError
64
- puts "Jeweler not available. To generate gem install it with: gem install jeweler"
65
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0
1
+ 3.1.1
@@ -63,7 +63,7 @@ module StudioApi
63
63
  # @return (String) response body from studio
64
64
  # @raise [ActiveResource::ConnectionError] when problem occur during connection
65
65
  def get(path)
66
- do_request Net::HTTP::Get.new Util.join_relative_url @connection.uri.request_uri,path
66
+ do_request(Net::HTTP::Get.new(Util.join_relative_url(@connection.uri.request_uri,path)))
67
67
  end
68
68
 
69
69
  # sends delete request
@@ -72,7 +72,7 @@ module StudioApi
72
72
  # @raise [ActiveResource::ConnectionError] when problem occur during connection
73
73
  def delete(path)
74
74
  #Even it is not dry I want to avoid meta programming with dynamic code evaluation so code is clear
75
- do_request Net::HTTP::Delete.new Util.join_relative_url @connection.uri.request_uri,path
75
+ do_request(Net::HTTP::Delete.new(Util.join_relative_url(@connection.uri.request_uri,path)))
76
76
  end
77
77
 
78
78
  # sends post request
@@ -81,7 +81,7 @@ module StudioApi
81
81
  # @return (String) response body from studio
82
82
  # @raise [ActiveResource::ConnectionError] when problem occur during connection
83
83
  def post(path,data={})
84
- request = Net::HTTP::Post.new Util.join_relative_url @connection.uri.request_uri,path
84
+ request = Net::HTTP::Post.new(Util.join_relative_url(@connection.uri.request_uri,path))
85
85
  set_data(request,data) unless data.empty?
86
86
  do_request request
87
87
  end
@@ -92,7 +92,7 @@ module StudioApi
92
92
  # @return (String) response body from studio
93
93
  # @raise [ActiveResource::ConnectionError] when problem occur during connection
94
94
  def put(path,data={})
95
- request = Net::HTTP::Put.new Util.join_relative_url @connection.uri.request_uri,path
95
+ request = Net::HTTP::Put.new(Util.join_relative_url(@connection.uri.request_uri,path))
96
96
  set_data(request,data) unless data.empty?
97
97
  do_request request
98
98
  end
@@ -12,6 +12,9 @@ module StudioApi
12
12
  # rb.save!
13
13
  # sleep 5
14
14
  # rb.cancel
15
+ #
16
+ # An ImageAlreadyExists exception is raised when force parameter is not
17
+ # specified and there's already a build with the same version.
15
18
  class RunningBuild < ActiveResource::Base
16
19
  extend StudioResource
17
20
 
@@ -19,6 +22,19 @@ module StudioApi
19
22
 
20
23
  alias_method :cancel, :destroy
21
24
 
25
+ def save
26
+ response = super
27
+ rescue ActiveResource::BadRequest => e
28
+ tree = XmlSimple.xml_in(e.response.body)
29
+ code = tree["code"][0]
30
+ if code == "image_already_exists"
31
+ message = tree["message"][0]
32
+ raise ImageAlreadyExists.new message
33
+ else
34
+ raise e
35
+ end
36
+ end
37
+
22
38
  private
23
39
  #overwrite create as studio doesn't interact well with enclosed parameters
24
40
  def create
@@ -32,4 +48,7 @@ private
32
48
  end
33
49
  end
34
50
  end
51
+
52
+ class ImageAlreadyExists < StandardError
53
+ end
35
54
  end
@@ -0,0 +1,98 @@
1
+ Fri May 14:30:55 CEST 2011 Flavio Castelli <flavio@castelli.name>
2
+
3
+ - code refactorying of the unit tests
4
+ - better handling of errors raised during image building
5
+ - created 3.1.1
6
+
7
+ -------------------------------------------------------------------
8
+ Wed Apr 6 06:43:08 UTC 2011 - jreidinger@novell.com
9
+
10
+ - add support for test drive and fixed test( contributed by
11
+ bjorn.maeland@gmail.com https://github.com/bmaland)
12
+ - 3.1.0
13
+
14
+ -------------------------------------------------------------------
15
+ Mon Feb 14 14:48:15 UTC 2011 - jreidinger@novell.com
16
+
17
+ - split doc and tests from rest of rpms packages to save space
18
+ - fix dependency in gem for active_resource
19
+ - improve summary
20
+ - 3.0.2
21
+
22
+ -------------------------------------------------------------------
23
+ Mon Feb 14 13:57:24 UTC 2011 - jreidinger@novell.com
24
+
25
+ - note in gem description link to suse studio public instance
26
+ (thanks to flavio)
27
+ - relicense to GPLv2 or The Ruby License
28
+ - 3.0.1
29
+
30
+ -------------------------------------------------------------------
31
+ Wed Feb 2 15:14:03 UTC 2011 - jreidinger@novell.com
32
+
33
+ - allow to use studio API v2
34
+ - 3.0.0
35
+
36
+ -------------------------------------------------------------------
37
+ Wed Jan 26 14:19:44 UTC 2011 - jreidinger@novell.com
38
+
39
+ - fix crash if software map is empty
40
+ - 2.4.0
41
+
42
+ -------------------------------------------------------------------
43
+ Thu Dec 16 12:04:43 UTC 2010 - jreidinger@novell.com
44
+
45
+ - fix compatibility with rails 3.0
46
+ - 2.3.0
47
+
48
+ -------------------------------------------------------------------
49
+ Thu Dec 9 12:15:22 UTC 2010 - jreidinger@novell.com
50
+
51
+ - fix uploading gpg key with File object
52
+ - fix studio status in studio maintenance mode
53
+ - add to documentation example of mocking
54
+ - 2.2.0
55
+
56
+ -------------------------------------------------------------------
57
+ Tue Nov 30 13:43:58 UTC 2010 - jreidinger@novell.com
58
+
59
+ - fix passing options to installed software
60
+ - 2.1.0
61
+
62
+ -------------------------------------------------------------------
63
+ Mon Nov 29 16:50:21 UTC 2010 - jreidinger@novell.com
64
+
65
+ - add ability too pass more parameters to installed software
66
+ - 2.0.0
67
+
68
+ -------------------------------------------------------------------
69
+ Mon Nov 29 15:09:19 UTC 2010 - jreidinger@novell.com
70
+
71
+ - improve escaping of parameters
72
+ - fix uploading gpg_key as file
73
+ - 1.2.0
74
+
75
+ -------------------------------------------------------------------
76
+ Fri Nov 19 14:12:18 UTC 2010 - jreidinger@novell.com
77
+
78
+ - fix issue with empty body of post and put
79
+ - 1.0.1
80
+
81
+ -------------------------------------------------------------------
82
+ Fri Nov 19 09:53:38 UTC 2010 - jreidinger@novell.com
83
+
84
+ - consistent behavior for uploading/downloading
85
+ - 1.0.0
86
+
87
+ -------------------------------------------------------------------
88
+ Mon Nov 15 13:11:38 UTC 2010 - jreidinger@novell.com
89
+
90
+ - improve documentation and return better return values when using
91
+ direct requests
92
+ - 0.2.0
93
+
94
+ -------------------------------------------------------------------
95
+ Fri Nov 12 15:40:23 UTC 2010 - jreidinger@novell.com
96
+
97
+ - initial submit
98
+
@@ -0,0 +1,89 @@
1
+ #
2
+ # spec file for package rubygem-studio_api
3
+ #
4
+ # Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
5
+ #
6
+ # All modifications and additions to the file contributed by third parties
7
+ # remain the property of their copyright owners, unless otherwise agreed
8
+ # upon. The license for this file, and modifications and additions to the
9
+ # file, is the same license as for the pristine package itself (unless the
10
+ # license for the pristine package is not an Open Source License, in which
11
+ # case the license is the MIT License). An "Open Source License" is a
12
+ # license that conforms to the Open Source Definition (Version 1.9)
13
+ # published by the Open Source Initiative.
14
+
15
+ # Please submit bugfixes or comments via http://bugs.opensuse.org/
16
+ #
17
+
18
+ # norootforbuild
19
+ Name: rubygem-studio_api
20
+ Version: <VERSION>
21
+ Release: 0
22
+ %define mod_name studio_api
23
+ #
24
+ Group: Development/Languages/Ruby
25
+ License: GPLv2 or The Ruby License
26
+ #
27
+ BuildRoot: %{_tmppath}/%{name}-%{version}-build
28
+ BuildRequires: rubygems_with_buildroot_patch
29
+ %rubygems_requires
30
+ BuildRequires: rubygem-activeresource >= 1.3.8
31
+ Requires: rubygem-activeresource >= 1.3.8
32
+ BuildRequires: rubygem-xml-simple >= 1.0.0
33
+ Requires: rubygem-xml-simple >= 1.0.0
34
+ #
35
+ Url: http://github.com/jreidinger/studio_api
36
+ Source: %{mod_name}-%{version}.gem
37
+ #
38
+ Summary: Intuitive ruby bindings to Studio Api Interface
39
+ %description
40
+ Studio Api makes it easier to use SuSE Studio (http://susestudio.com) via API.
41
+ Instead of adapting each ActiveResource to its behavior and
42
+ manually adding multipart file upload it wrapp in in Active
43
+ Resource like interface. It is possible to define credentials
44
+ for whole api, or use it per partes, so it allow using it for
45
+ different studio users together.
46
+
47
+ %package doc
48
+ Summary: RDoc documentation for %{mod_name}
49
+ Group: Development/Languages/Ruby
50
+ License: GPLv2 or The Ruby License
51
+ Requires: %{name} = %{version}
52
+ %description doc
53
+ Documentation generated at gem installation time.
54
+ Usually in RDoc and RI formats.
55
+
56
+
57
+ %package testsuite
58
+ Summary: Test suite for %{mod_name}
59
+ Group: Development/Languages/Ruby
60
+ License: GPLv2 or The Ruby License
61
+ Requires: %{name} = %{version}
62
+ %description testsuite
63
+ Test::Unit or RSpec files, useful for developers.
64
+
65
+
66
+ %prep
67
+ %build
68
+ %install
69
+ %gem_install %{S:0}
70
+
71
+ %clean
72
+ %{__rm} -rf %{buildroot}
73
+
74
+ %files
75
+ %defattr(-,root,root,-)
76
+ %{_libdir}/ruby/gems/%{rb_ver}/cache/%{mod_name}-%{version}.gem
77
+ %{_libdir}/ruby/gems/%{rb_ver}/gems/%{mod_name}-%{version}/
78
+ %exclude %{_libdir}/ruby/gems/%{rb_ver}/gems/%{mod_name}-%{version}/test
79
+ %{_libdir}/ruby/gems/%{rb_ver}/specifications/%{mod_name}-%{version}.gemspec
80
+
81
+ %files doc
82
+ %defattr(-,root,root,-)
83
+ %doc %{_libdir}/ruby/gems/%{rb_ver}/doc/%{mod_name}-%{version}/
84
+
85
+ %files testsuite
86
+ %defattr(-,root,root,-)
87
+ %{_libdir}/ruby/gems/%{rb_ver}/gems/%{mod_name}-%{version}/test
88
+
89
+ %changelog
@@ -1,219 +1,213 @@
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'
1
+ require 'test_helper'
11
2
 
12
3
  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
-
4
+
19
5
  def setup
20
- @connection = StudioApi::Connection.new("test","test","http://localhost/api/")
6
+ @appliance_id = 266657
7
+ @repo_id = 6345
8
+
9
+ FakeWeb.clean_registry
10
+ FakeWeb.allow_net_connect = false
11
+ @connection = StudioApi::Connection.new(@@username, @@password,"http://localhost/api/")
21
12
  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
- conf_out = respond_load "configuration.xml"
29
- ActiveResource::HttpMock.respond_to do |mock|
30
- mock.get "/api/appliances", {"Authorization"=>"Basic dGVzdDp0ZXN0"},appliances_out,200
31
- mock.get "/api/appliances/#{APPLIANCE_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"},appliance_out,200
32
- mock.get "/api/appliances/#{APPLIANCE_ID}/status", {"Authorization"=>"Basic dGVzdDp0ZXN0"},status_out,200
33
- mock.delete "/api/appliances/#{APPLIANCE_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"},appliance_out,200
34
- mock.get "/api/appliances/#{APPLIANCE_ID}/repositories", {"Authorization"=>"Basic dGVzdDp0ZXN0"},repositories_out,200
35
- mock.post "/api/appliances/#{APPLIANCE_ID}/cmd/add_repository?repo_id=#{REPO_ID}",{"Authorization"=>"Basic dGVzdDp0ZXN0"},repositories_out,200
36
- mock.post "/api/appliances/#{APPLIANCE_ID}/cmd/add_user_repository",{"Authorization"=>"Basic dGVzdDp0ZXN0"},repositories_out,200
37
- mock.get "/api/appliances/#{APPLIANCE_ID}/gpg_keys", {"Authorization"=>"Basic dGVzdDp0ZXN0"},gpg_keys_out,200
38
- mock.get "/api/appliances/#{APPLIANCE_ID}/gpg_keys/1976", {"Authorization"=>"Basic dGVzdDp0ZXN0"},gpg_key_out,200
39
- mock.delete "/api/appliances/#{APPLIANCE_ID}/gpg_keys/1976", {"Authorization"=>"Basic dGVzdDp0ZXN0"},gpg_key_out,200
40
- mock.get "/api/appliances/#{APPLIANCE_ID}/configuration", {"Authorization"=>"Basic dGVzdDp0ZXN0"},conf_out,200
41
- end
42
13
  end
43
14
 
44
15
  def teardown
45
- Mocha::Mockery.instance.stubba.unstub_all
16
+ FakeWeb.allow_net_connect = false
46
17
  end
47
18
 
48
19
  def test_find_all
20
+ register_fake_response_from_file :get, '/api/appliances', 'appliances.xml'
49
21
  res = StudioApi::Appliance.find :all
50
22
  assert_equal 7,res.size
51
23
  end
52
24
 
53
- def test_find_one
54
- res = StudioApi::Appliance.find APPLIANCE_ID
55
- assert_equal APPLIANCE_ID.to_s, res.id
56
- end
57
-
58
- def test_status
59
- res = StudioApi::Appliance.find APPLIANCE_ID
60
- assert_equal "ok", res.status.state
61
- end
62
-
63
- def test_maintenance_status
64
- status_out = respond_load "status-broken.xml"
65
- ActiveResource::HttpMock.respond_to do |mock|
66
- mock.get "/api/appliances/#{APPLIANCE_ID}/status", {"Authorization"=>"Basic dGVzdDp0ZXN0"},status_out,200
67
- end
68
- res = StudioApi::Appliance.new(:id => APPLIANCE_ID)
69
- assert_equal "error", res.status.state
70
- end
71
-
72
- def test_clone
73
- appliance_out = respond_load "appliance.xml"
74
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances?clone_from=#{APPLIANCE_ID}",{}).returns(appliance_out).once
75
- assert StudioApi::Appliance.clone APPLIANCE_ID
76
- end
77
-
78
- def test_manifest
79
- manifest_out = respond_load "manifest.xml"
80
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/appliances/#{APPLIANCE_ID}/software/manifest/vmx").returns(manifest_out).once
81
- assert StudioApi::Appliance.new(:id => APPLIANCE_ID).manifest_file "vmx"
82
- end
83
-
84
- def test_delete
85
- assert StudioApi::Appliance.delete APPLIANCE_ID
86
- assert StudioApi::Appliance.find(APPLIANCE_ID).destroy #same but different way
87
- end
88
-
89
- def test_repositories
90
- res = StudioApi::Appliance.new(:id => APPLIANCE_ID).repositories
91
- assert_equal 5,res.size
92
- end
93
-
94
- def test_repository_remove
95
- repositories_out = respond_load "repositories.xml"
96
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/remove_repository?repo_id=#{REPO_ID}").returns(repositories_out)
97
- appliance = StudioApi::Appliance.new(:id => APPLIANCE_ID)
98
- assert appliance.remove_repository REPO_ID
99
- repo = appliance.repositories.detect { |r| r.id == REPO_ID.to_s}
100
- assert repo.destroy #another way to delete repository
101
- end
102
-
103
- def test_repository_add
104
- repositories_out = respond_load "repositories.xml"
105
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/add_repository?repo_id=#{REPO_ID}").returns(repositories_out)
106
- assert StudioApi::Appliance.new(:id => APPLIANCE_ID).add_repository REPO_ID
107
- end
108
-
109
- def test_user_repository_add
110
- repositories_out = respond_load "repositories.xml"
111
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/add_user_repository").returns(repositories_out)
112
- assert StudioApi::Appliance.new(:id => APPLIANCE_ID).add_user_repository
113
- end
114
-
115
- def test_configuration
116
- conf_out = respond_load "configuration.xml"
117
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/appliances/#{APPLIANCE_ID}/configuration").returns(conf_out).once
118
- conf= StudioApi::Appliance.new(:id => APPLIANCE_ID).configuration
119
- assert conf.to_xml
120
- assert conf
121
- end
122
-
123
- def test_user_repository_add
124
- users0 = respond_load "users_0.xml"
125
- users1 = respond_load "users_1.xml"
126
- users2 = respond_load "users_2.xml"
127
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/sharing/test1").returns(users2).once
128
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/appliances/#{APPLIANCE_ID}/sharing").returns(users1).once
129
- StudioApi::GenericRequest.any_instance.stubs(:delete).with("/appliances/#{APPLIANCE_ID}/sharing/test1").returns(users1).once
130
- assert_equal 1, StudioApi::Appliance.new(:id => APPLIANCE_ID).users.size
131
- assert_equal 2, StudioApi::Appliance.new(:id => APPLIANCE_ID).add_user("test1").size
132
- assert_equal 1, StudioApi::Appliance.new(:id => APPLIANCE_ID).remove_user("test1").size
133
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/appliances/#{APPLIANCE_ID}/sharing").returns(users0).once
134
- assert_equal 0, StudioApi::Appliance.new(:id => APPLIANCE_ID).users.size
135
- end
136
-
137
- def test_selected_software
138
- software_out = respond_load "software.xml"
139
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/appliances/#{APPLIANCE_ID}/software").returns(software_out).once
140
- res = StudioApi::Appliance.new(:id => APPLIANCE_ID).selected_software
141
- assert_equal 48,res.size
142
- assert res.any? {|r| r.is_a? StudioApi::Pattern }, "Pattern is not loaded"
143
- assert res.any? {|r| r.name = "sysvinit" && r.version == "2.86-200.1" }, "package with specified version not found"
144
- end
145
-
146
- def test_installed_software
147
- software_in_out = respond_load "software_installed.xml"
148
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/appliances/#{APPLIANCE_ID}/software/installed?build_id=1").returns(software_in_out).once
149
- res = StudioApi::Appliance.new(:id => APPLIANCE_ID).installed_software :build_id => 1
150
- assert_equal 608,res.size
151
- assert res.any? {|r| r.is_a? StudioApi::Pattern }, "Pattern is not loaded"
152
- diag = res.find { |p| p.name == "3ddiag"}
153
- assert_equal "0.742-32.25",diag.version
154
- assert_equal 6347,diag.repository_id
155
- end
156
-
157
- def test_search_software
158
- software_se_out = respond_load "software_search.xml"
159
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/appliances/#{APPLIANCE_ID}/software/search?q=qt").returns(software_se_out).once
160
- res = StudioApi::Appliance.new(:id => APPLIANCE_ID).search_software "qt"
161
- assert_equal 54,res.size
162
- assert res.any? {|r| r.is_a? StudioApi::Pattern }, "Pattern is not loaded"
163
- apport = res.find { |p| p.name == "apport-qt"}
164
- assert_equal "0.114-12.7.10",apport.version
165
- assert_equal 6347,apport.repository_id
166
- end
167
-
168
- SOFTWARE_FAKE_RESPONSE= <<EOF
169
- <success>
170
- <details>
171
- <status>
172
- <state>changed</state>
173
- <packages_added>13</packages_added>
174
- <packages_removed>0</packages_removed>
175
- </status>
176
- </details>
177
- </success>
178
- EOF
179
- def test_manipulate_with_packages_and_pattern
180
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/add_package?name=3ddiag",:name => "3ddiag").returns(SOFTWARE_FAKE_RESPONSE).once
181
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/remove_package?name=3ddiag",:name => "3ddiag").returns(SOFTWARE_FAKE_RESPONSE).once
182
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/add_pattern?name=kde4", :name => "kde4").returns(SOFTWARE_FAKE_RESPONSE).once
183
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/remove_pattern?name=kde4",:name => "kde4").returns(SOFTWARE_FAKE_RESPONSE).once
184
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/ban_package?name=3ddiag",:name => "3ddiag").returns(SOFTWARE_FAKE_RESPONSE).once
185
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/cmd/unban_package?name=3ddiag",:name => "3ddiag").returns(SOFTWARE_FAKE_RESPONSE).once
186
- appliance = StudioApi::Appliance.new(:id => APPLIANCE_ID)
187
- assert appliance.add_package "3ddiag"
188
- assert appliance.remove_package "3ddiag"
189
- assert appliance.add_pattern "kde4"
190
- assert appliance.remove_pattern "kde4"
191
- assert appliance.ban_package "3ddiag"
192
- assert appliance.unban_package "3ddiag"
193
- end
194
-
195
- def test_gpg_keys
196
- res = StudioApi::Appliance.new(:id => APPLIANCE_ID).gpg_keys
197
- assert_equal 3,res.size
198
- end
199
-
200
- def test_gpg_key
201
- res = StudioApi::Appliance.new(:id => APPLIANCE_ID).gpg_key 1976
202
- assert_equal 1976, res.id.to_i
203
- assert_equal "rpm", res.target
204
- end
205
-
206
- def test_delete_gpg_key
207
- assert StudioApi::Appliance::GpgKey.delete 1976, :appliance_id => APPLIANCE_ID
208
- res = StudioApi::Appliance.new(:id => APPLIANCE_ID).gpg_key 1976
209
- assert res.destroy
210
- end
211
-
212
- def test_add_gpg_key
213
- gpg_key_out = respond_load "gpg_key.xml"
214
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/gpg_keys?name=test&target=rpm&key=test",{}).returns(gpg_key_out)
215
- StudioApi::GenericRequest.any_instance.stubs(:post).with("/appliances/#{APPLIANCE_ID}/gpg_keys?name=test&key=test&target=rpm",{}).returns(gpg_key_out)
216
- assert StudioApi::Appliance::GpgKey.create APPLIANCE_ID, "test", "test"
217
- assert StudioApi::Appliance.new(:id => APPLIANCE_ID).add_gpg_key "test", "test"
218
- end
25
+ def test_find_one
26
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}",
27
+ 'appliance.xml'
28
+ res = StudioApi::Appliance.find @appliance_id
29
+ assert_equal @appliance_id.to_s, res.id
30
+ end
31
+
32
+ def test_status
33
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}",
34
+ 'appliance.xml'
35
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/status",
36
+ 'status.xml'
37
+ res = StudioApi::Appliance.find @appliance_id
38
+ assert_equal "ok", res.status.state
39
+ end
40
+
41
+ def test_maintenance_status
42
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/status",
43
+ 'status-broken.xml'
44
+ res = StudioApi::Appliance.new(:id => @appliance_id)
45
+ assert_equal "error", res.status.state
46
+ end
47
+
48
+ def test_clone
49
+ register_fake_response_from_file :post, "/api/appliances?clone_from=#{@appliance_id}",
50
+ 'appliance.xml'
51
+ assert StudioApi::Appliance.clone(@appliance_id)
52
+ end
53
+
54
+ def test_manifest
55
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/software/manifest/vmx",
56
+ 'manifest.xml'
57
+ assert StudioApi::Appliance.new(:id => @appliance_id).manifest_file("vmx")
58
+ end
59
+
60
+ def test_delete
61
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}",
62
+ 'appliance.xml'
63
+ register_fake_response_from_file :delete, "/api/appliances/#{@appliance_id}",
64
+ 'appliance.xml'
65
+ assert StudioApi::Appliance.delete(@appliance_id)
66
+ assert StudioApi::Appliance.find(@appliance_id).destroy #same but different way
67
+ end
68
+
69
+ def test_repositories
70
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/repositories",
71
+ 'repositories.xml'
72
+ res = StudioApi::Appliance.new(:id => @appliance_id).repositories
73
+ assert_equal 5,res.size
74
+ end
75
+
76
+ def test_repository_remove
77
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/repositories",
78
+ 'repositories.xml'
79
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/cmd/remove_repository?repo_id=#{@repo_id}",
80
+ 'repositories.xml'
81
+ appliance = StudioApi::Appliance.new(:id => @appliance_id)
82
+ assert appliance.remove_repository(@repo_id)
83
+ repo = appliance.repositories.detect { |r| r.id == @repo_id.to_s}
84
+ assert repo.destroy #another way to delete repository
85
+ end
86
+
87
+ def test_repository_add
88
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/cmd/add_repository?repo_id=#{@repo_id}",
89
+ 'repositories.xml'
90
+ assert StudioApi::Appliance.new(:id => @appliance_id).add_repository(@repo_id)
91
+ end
92
+
93
+ def test_user_repository_add
94
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/cmd/add_user_repository",
95
+ 'repositories.xml'
96
+ assert StudioApi::Appliance.new(:id => @appliance_id).add_user_repository
97
+ end
98
+
99
+ def test_configuration
100
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/configuration",
101
+ 'configuration.xml'
102
+ conf= StudioApi::Appliance.new(:id => @appliance_id).configuration
103
+ assert conf.to_xml
104
+ assert conf
105
+ end
106
+
107
+ def test_user_repository_add
108
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/sharing/test1",
109
+ 'users_2.xml'
110
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/sharing",
111
+ 'users_1.xml'
112
+ register_fake_response_from_file :delete, "/api/appliances/#{@appliance_id}/sharing/test1",
113
+ 'users_1.xml'
114
+ assert_equal 1, StudioApi::Appliance.new(:id => @appliance_id).users.size
115
+ assert_equal 2, StudioApi::Appliance.new(:id => @appliance_id).add_user("test1").size
116
+ assert_equal 1, StudioApi::Appliance.new(:id => @appliance_id).remove_user("test1").size
117
+
118
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/sharing",
119
+ 'users_0.xml'
120
+ assert_equal 0, StudioApi::Appliance.new(:id => @appliance_id).users.size
121
+ end
122
+
123
+ def test_selected_software
124
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/software",
125
+ 'software.xml'
126
+ res = StudioApi::Appliance.new(:id => @appliance_id).selected_software
127
+ assert_equal 48,res.size
128
+ assert res.any? {|r| r.is_a? StudioApi::Pattern }, "Pattern is not loaded"
129
+ assert res.any? {|r| r.name = "sysvinit" && r.version == "2.86-200.1" }, "package with specified version not found"
130
+ end
131
+
132
+ def test_installed_software
133
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/software/installed?build_id=1",
134
+ 'software_installed.xml'
135
+ res = StudioApi::Appliance.new(:id => @appliance_id).installed_software :build_id => 1
136
+ assert_equal 608,res.size
137
+ assert res.any? {|r| r.is_a? StudioApi::Pattern }, "Pattern is not loaded"
138
+ diag = res.find { |p| p.name == "3ddiag"}
139
+ assert_equal "0.742-32.25",diag.version
140
+ assert_equal 6347,diag.repository_id
141
+ end
142
+
143
+ def test_search_software
144
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/software/search?q=qt",
145
+ 'software_search.xml'
146
+
147
+ res = StudioApi::Appliance.new(:id => @appliance_id).search_software "qt"
148
+ assert_equal 54,res.size
149
+ assert res.any? {|r| r.is_a? StudioApi::Pattern }, "Pattern is not loaded"
150
+ apport = res.find { |p| p.name == "apport-qt"}
151
+ assert_equal "0.114-12.7.10",apport.version
152
+ assert_equal 6347,apport.repository_id
153
+ end
154
+
155
+ def test_manipulate_with_packages_and_pattern
156
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/cmd/add_package?name=3ddiag",
157
+ 'software_fake_response.xml'
158
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/cmd/remove_package?name=3ddiag",
159
+ 'software_fake_response.xml'
160
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/cmd/add_pattern?name=kde4",
161
+ 'software_fake_response.xml'
162
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/cmd/remove_pattern?name=kde4",
163
+ 'software_fake_response.xml'
164
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/cmd/ban_package?name=3ddiag",
165
+ 'software_fake_response.xml'
166
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/cmd/unban_package?name=3ddiag",
167
+ 'software_fake_response.xml'
168
+
169
+ appliance = StudioApi::Appliance.new(:id => @appliance_id)
170
+ assert appliance.add_package("3ddiag")
171
+ assert appliance.remove_package("3ddiag")
172
+ assert appliance.add_pattern("kde4")
173
+ assert appliance.remove_pattern("kde4")
174
+ assert appliance.ban_package("3ddiag")
175
+ assert appliance.unban_package("3ddiag")
176
+ end
177
+
178
+ def test_gpg_keys
179
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/gpg_keys",
180
+ 'gpg_keys.xml'
181
+ res = StudioApi::Appliance.new(:id => @appliance_id).gpg_keys
182
+ assert_equal 3,res.size
183
+ end
184
+
185
+ def test_gpg_key
186
+ gpg_key_id = 1976
187
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/gpg_keys/#{gpg_key_id}",
188
+ 'gpg_key.xml'
189
+ res = StudioApi::Appliance.new(:id => @appliance_id).gpg_key(gpg_key_id)
190
+ assert_equal gpg_key_id, res.id.to_i
191
+ assert_equal "rpm", res.target
192
+ end
193
+
194
+ def test_delete_gpg_key
195
+ gpg_key_id = 1976
196
+ register_fake_response_from_file :get, "/api/appliances/#{@appliance_id}/gpg_keys/#{gpg_key_id}",
197
+ 'gpg_key.xml'
198
+ register_fake_response_from_file :delete, "/api/appliances/#{@appliance_id}/gpg_keys/#{gpg_key_id}",
199
+ 'gpg_key.xml'
200
+ assert StudioApi::Appliance::GpgKey.delete(gpg_key_id, :appliance_id => @appliance_id)
201
+ res = StudioApi::Appliance.new(:id => @appliance_id).gpg_key gpg_key_id
202
+ assert res.destroy
203
+ end
204
+
205
+ def test_add_gpg_key
206
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/gpg_keys?name=test&target=rpm&key=test",
207
+ 'gpg_key.xml'
208
+ register_fake_response_from_file :post, "/api/appliances/#{@appliance_id}/gpg_keys?name=test&key=test&target=rpm",
209
+ 'gpg_key.xml'
210
+ assert StudioApi::Appliance::GpgKey.create(@appliance_id, "test", "test")
211
+ assert StudioApi::Appliance.new(:id => @appliance_id).add_gpg_key("test", "test")
212
+ end
219
213
  end