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/test/build_test.rb CHANGED
@@ -1,45 +1,42 @@
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'
1
+ require 'test_helper'
9
2
 
10
3
  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
4
 
18
5
  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"
6
+ @build_id = 509559
7
+ @appliance_id = 269186
24
8
 
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
9
+ FakeWeb.clean_registry
10
+ FakeWeb.allow_net_connect = false
11
+ @connection = StudioApi::Connection.new(@@username, @@password,"http://localhost/api/")
12
+ StudioApi::Build.studio_connection = @connection
13
+ end
14
+
15
+ def teardown
16
+ FakeWeb.allow_net_connect = false
30
17
  end
31
18
 
32
19
  def test_find
33
- res = StudioApi::Build.find :all, :params => {:appliance_id => APPLIANCE_ID}
20
+ register_fake_response_from_file :get, "/api/builds?appliance_id=#{@appliance_id}",
21
+ 'builds.xml'
22
+ res = StudioApi::Build.find :all, :params => {:appliance_id => @appliance_id}
34
23
  assert_equal 1, res.size
35
- res = StudioApi::Build.find BUILD_ID
24
+
25
+ register_fake_response_from_file :get, "/api/builds/#{@build_id}",
26
+ 'build.xml'
27
+ res = StudioApi::Build.find @build_id
36
28
  assert_equal "true", res.expired
37
29
  end
38
30
 
39
31
  def test_delete
40
- build = StudioApi::Build.find BUILD_ID
32
+ register_fake_response_from_file :get, "/api/builds/#{@build_id}",
33
+ 'build.xml'
34
+ register_fake_response_from_file :delete, "/api/builds/#{@build_id}",
35
+ 'build.xml'
36
+
37
+ build = StudioApi::Build.find @build_id
41
38
  assert build.destroy
42
- assert StudioApi::Build.delete BUILD_ID
39
+ assert StudioApi::Build.delete @build_id
43
40
  end
44
41
 
45
42
  end
@@ -1,19 +1,19 @@
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'
1
+ require 'test_helper'
8
2
 
9
3
  class ConnectionTest < Test::Unit::TestCase
10
4
  def setup
11
- @connection = StudioApi::Connection.new("test","test","http://localhost/api/user")
5
+ FakeWeb.clean_registry
6
+ FakeWeb.allow_net_connect = false
7
+ @connection = StudioApi::Connection.new(@@username, @@password,"http://localhost/api/")
8
+ end
9
+
10
+ def teardown
11
+ FakeWeb.allow_net_connect = false
12
12
  end
13
13
 
14
- FAKE_API_VERSION_RESPONSE = "<version>1.0</version>"
15
14
  def test_api_version
16
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/api_version").returns(FAKE_API_VERSION_RESPONSE).once
15
+ register_fake_response_from_file :get, "/api/api_version",
16
+ 'api_version.xml'
17
17
  assert_equal "1.0",@connection.api_version
18
18
  @connection.api_version #test caching, if it again call, then mocha raise exception
19
19
  end
data/test/file_test.rb CHANGED
@@ -1,52 +1,49 @@
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'
1
+ require 'test_helper'
10
2
 
11
3
  #FileTest cause collistion of names
12
4
  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
5
 
20
6
  def setup
21
- @connection = StudioApi::Connection.new("test","test","http://localhost")
7
+ @appliance_id=488
8
+ @file_id = 1234765
9
+
10
+ FakeWeb.clean_registry
11
+ FakeWeb.allow_net_connect = false
12
+ @connection = StudioApi::Connection.new(@@username, @@password,"http://localhost/api/")
22
13
  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
14
  end
32
15
 
33
16
  def test_find
34
- res = StudioApi::File.find :all, :params => { :appliance_id => APPLIANCE_ID }
17
+ register_fake_response_from_file :get, "/api/files?appliance_id=#{@appliance_id}",
18
+ 'files.xml'
19
+ res = StudioApi::File.find :all, :params => { :appliance_id => @appliance_id }
35
20
  assert_equal 1, res.size
36
21
  assert_equal "http://susestudio.com/file/download/214486/1234765", res[0].download_url
37
- res = StudioApi::File.find FILE_ID
22
+
23
+ register_fake_response_from_file :get, "/api/files/#{@file_id}",
24
+ 'file.xml'
25
+ res = StudioApi::File.find @file_id
38
26
  assert_equal "http://susestudio.com/file/download/214486/1234765", res.download_url
39
27
  end
40
28
 
41
29
  def test_delete
42
- assert StudioApi::File.find(FILE_ID).destroy
43
- assert StudioApi::File.delete FILE_ID #different way
30
+ register_fake_response_from_file :get, "/api/files/#{@file_id}",
31
+ 'file.xml'
32
+ register_fake_response_from_file :delete, "/api/files/#{@file_id}",
33
+ 'file.xml'
34
+ assert StudioApi::File.find(@file_id).destroy
35
+ assert StudioApi::File.delete @file_id #different way
44
36
  end
45
37
 
46
38
  def test_update
47
- f = StudioApi::File.find(FILE_ID)
48
- f.path = "/tmp"
49
- assert f.save
39
+ register_fake_response_from_file :get, "/api/files/#{@file_id}",
40
+ 'file.xml'
41
+ register_fake_response_from_file :put, "/api/files/#{@file_id}",
42
+ 'file.xml'
43
+
44
+ f = StudioApi::File.find(@file_id)
45
+ f.path = "/tmp"
46
+ assert f.save
50
47
  end
51
48
  end
52
49
 
data/test/gallery_test.rb CHANGED
@@ -1,48 +1,38 @@
1
- require 'rubygems'
2
- require 'active_support'
3
- $:.unshift File.join( File.dirname(__FILE__),'..','lib')
4
- require 'studio_api/gallery'
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 GalleryTest < Test::Unit::TestCase
13
- APPLIANCE_ID = 130166
14
- APPL_VERSION = "0.1.1"
15
- def respond_load name
16
- IO.read(File.join(File.dirname(__FILE__),"responses",name))
17
- end
18
-
19
4
  def setup
20
- @connection = StudioApi::Connection.new("test","test","http://localhost/api/")
5
+ @appliance_id = 130166
6
+ @appliance_version = "0.1.1"
7
+
8
+ FakeWeb.clean_registry
9
+ FakeWeb.allow_net_connect = false
10
+ @connection = StudioApi::Connection.new(@@username, @@password,"http://localhost/api/")
21
11
  StudioApi::Util.configure_studio_connection @connection
22
12
  end
23
13
 
24
14
  def teardown
25
- Mocha::Mockery.instance.stubba.unstub_all
15
+ FakeWeb.allow_net_connect = false
26
16
  end
27
17
 
28
18
  def test_find
29
- gallery_out = respond_load "gallery.xml"
30
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/gallery/appliances?popular&per_page=10").returns(gallery_out)
19
+ register_fake_response_from_file :get, "/api/gallery/appliances?popular&per_page=10",
20
+ 'gallery.xml'
31
21
  out = StudioApi::Gallery.find_appliance :popular, :per_page => 10
32
22
  assert_equal 10, out[:appliances].size
33
23
  end
34
24
 
35
25
  def test_appliance
36
- gallery_appliance_out = respond_load "gallery_appliance.xml"
37
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/gallery/appliances/#{APPLIANCE_ID}/version/#{APPL_VERSION}").returns(gallery_appliance_out)
38
- out = StudioApi::Gallery.appliance APPLIANCE_ID, APPL_VERSION
26
+ register_fake_response_from_file :get, "/api/gallery/appliances/#{@appliance_id}/version/#{@appliance_version}",
27
+ 'gallery_appliance.xml'
28
+ out = StudioApi::Gallery.appliance @appliance_id, @appliance_version
39
29
  assert out
40
30
  end
41
31
 
42
32
  def test_gallery_appliance_versions
43
- versions_out = respond_load "versions.xml"
44
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/gallery/appliances/#{APPLIANCE_ID}/versions").returns(versions_out)
45
- out = StudioApi::Gallery::Appliance.new(:id => APPLIANCE_ID).versions
33
+ register_fake_response_from_file :get, "/api/gallery/appliances/#{@appliance_id}/versions",
34
+ 'versions.xml'
35
+ out = StudioApi::Gallery::Appliance.new(:id => @appliance_id).versions
46
36
  assert_equal 6,out.size
47
37
  end
48
38
 
@@ -1,50 +1,44 @@
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'
1
+ require 'test_helper'
8
2
 
9
3
  class GenericRequestTest < Test::Unit::TestCase
10
4
  def setup
11
- Mocha::Mockery.instance.stubba.unstub_all
12
- @connection = StudioApi::Connection.new("test","test","http://localhost")
5
+ FakeWeb.clean_registry
6
+ FakeWeb.allow_net_connect = false
7
+ @connection = StudioApi::Connection.new(@@username, @@password,"http://localhost/api/")
8
+ StudioApi::Build.studio_connection = @connection
9
+
10
+ @test_response = "Test response"
13
11
  end
14
12
 
15
13
  def teardown
16
- Mocha::Mockery.instance.stubba.unstub_all
14
+ FakeWeb.allow_net_connect = false
17
15
  end
18
16
 
19
- ERROR_RESPONSE = <<EOF
20
- <error>
21
- <code>invalid_base_system</code>
22
- <message>Invalid base system.</message>
23
- </error>
24
- EOF
25
17
  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")
18
+ register_fake_response :get, "/api/test", @test_response
19
+ assert_equal @test_response, StudioApi::GenericRequest.new(@connection).get("test")
29
20
  end
30
21
 
31
22
  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")
23
+ register_fake_response :post, "/api/test", @test_response
24
+ assert_equal @test_response,
25
+ StudioApi::GenericRequest.new(@connection).post("test",:file => "/dev/zero")
35
26
  end
36
27
 
37
28
  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
29
+ error_response = <<-EOF
30
+ <error>
31
+ <code>invalid_base_system</code>
32
+ <message>Invalid base system.</message>
33
+ </error>
34
+ EOF
35
+ url = "http://#{@@username}:#{@@password}@localhost/api/test"
36
+ FakeWeb.register_uri(:get, url, :body => error_response,
37
+ :status => ["503", "Unavailable"])
38
+
39
+ assert_raises(ActiveResource::ServerError) do
40
+ StudioApi::GenericRequest.new(@connection).get("test")
46
41
  end
47
- assert_raises(ActiveResource::ServerError) { rq.get("test") }
48
42
  end
49
43
 
50
44
  def test_mime_type
@@ -56,7 +50,9 @@ EOF
56
50
  end
57
51
 
58
52
  def test_ssl_settings
59
- @connection = StudioApi::Connection.new("test","test","https://localhost",:ssl => { :verify_mode => OpenSSL::SSL::VERIFY_PEER, :ca_path => "/dev/null" })
53
+ @connection = StudioApi::Connection.new("test","test","https://localhost",
54
+ :ssl => { :verify_mode => OpenSSL::SSL::VERIFY_PEER,
55
+ :ca_path => "/dev/null" })
60
56
  rq = StudioApi::GenericRequest.new @connection
61
57
  http_var = rq.instance_variable_get("@http")
62
58
  assert http_var.use_ssl?
@@ -1,42 +1,38 @@
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'
1
+ require 'test_helper'
11
2
 
12
3
  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
4
  def setup
18
- @connection = StudioApi::Connection.new("test","test","http://localhost")
5
+ @repository_id = 6343
6
+
7
+ FakeWeb.clean_registry
8
+ FakeWeb.allow_net_connect = false
9
+ @connection = StudioApi::Connection.new(@@username, @@password,"http://localhost/api/")
19
10
  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
11
+ end
12
+
13
+ def teardown
14
+ FakeWeb.allow_net_connect = false
27
15
  end
28
16
 
29
17
  def test_find
18
+ register_fake_response_from_file :get, "/api/repositories?base_system=sle11sp1",
19
+ 'repositories.xml'
20
+
30
21
  res = StudioApi::Repository.find :all, :params => {:base_system => "sle11sp1"}
31
22
  assert_equal 5,res.size
32
- res = StudioApi::Repository.find REPOSITORY_ID
33
- assert_equal REPOSITORY_ID, res.id.to_i
23
+
24
+ register_fake_response_from_file :get, "/api/repositories/#{@repository_id}",
25
+ 'repository.xml'
26
+ res = StudioApi::Repository.find @repository_id
27
+ assert_equal @repository_id, res.id.to_i
34
28
  end
35
29
 
36
30
  def test_import
37
- res = StudioApi::Repository.import "http://test","test"
38
- assert res
39
- assert_equal REPOSITORY_ID, res.id.to_i
31
+ register_fake_response_from_file :post, "/api/repositories?name=test&url=http%3A%2F%2Ftest",
32
+ 'repository.xml'
33
+ res = StudioApi::Repository.import "http://test","test"
34
+ assert res
35
+ assert_equal @repository_id, res.id.to_i
40
36
  end
41
37
  end
42
38
 
@@ -1,12 +1,4 @@
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'
1
+ require 'test_helper'
10
2
 
11
3
  class MyTest < ActiveResource::Base
12
4
  extend StudioApi::StudioResource
@@ -0,0 +1 @@
1
+ <version>1.0</version>
@@ -0,0 +1,4 @@
1
+ <error>
2
+ <code>image_already_exists</code>
3
+ <message>Image already exists. Change version or type or force an overwrite.</message>
4
+ </error>
@@ -0,0 +1,9 @@
1
+ <success>
2
+ <details>
3
+ <status>
4
+ <state>changed</state>
5
+ <packages_added>13</packages_added>
6
+ <packages_removed>0</packages_removed>
7
+ </status>
8
+ </details>
9
+ </success>
data/test/rpm_test.rb CHANGED
@@ -1,59 +1,53 @@
1
- require 'rubygems'
2
- require 'active_support'
3
- require 'active_resource/http_mock'
4
- require 'mocha'
5
- require 'test/unit'
6
- require 'tempfile'
7
- $:.unshift File.join( File.dirname(__FILE__), '..', 'lib')
8
- require 'studio_api/rpm'
9
- require 'studio_api/connection'
10
- require 'studio_api/generic_request'
1
+ require 'test_helper'
11
2
 
12
3
  class RpmTest < Test::Unit::TestCase
13
- APPLIANCE_ID = 269186
14
- RPM_ID = 27653
15
-
16
- def respond_load name
17
- IO.read(File.join(File.dirname(__FILE__), "responses", name))
18
- end
19
4
 
20
5
  def setup
21
- @connection = StudioApi::Connection.new("test", "test", "http://localhost")
22
- StudioApi::Rpm.studio_connection = @connection
6
+ @appliance_id = 269186
7
+ @rpm_id = 27653
8
+ @rpm_data = "My lovely testing string\n Doodla da da da nicht"
23
9
 
24
- rpms_out = respond_load "rpms.xml"
25
- rpm_out = respond_load "rpm.xml"
10
+ FakeWeb.clean_registry
11
+ FakeWeb.allow_net_connect = false
12
+ @connection = StudioApi::Connection.new(@@username, @@password,"http://localhost/api/")
13
+ StudioApi::Rpm.studio_connection = @connection
14
+ end
26
15
 
27
- ActiveResource::HttpMock.respond_to do |mock|
28
- mock.get "/rpms?base_system=sle11_sp1", {"Authorization"=>"Basic dGVzdDp0ZXN0"}, rpms_out, 200
29
- mock.get "/rpms/#{RPM_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"}, rpm_out, 200
30
- mock.delete "/rpms/#{RPM_ID}", {"Authorization"=>"Basic dGVzdDp0ZXN0"}, rpm_out, 200
31
- end
16
+ def teardown
17
+ FakeWeb.allow_net_connect = false
32
18
  end
33
19
 
34
20
  def test_find
21
+ register_fake_response_from_file :get, "/api/rpms?base_system=sle11_sp1",
22
+ 'rpms.xml'
35
23
  res = StudioApi::Rpm.find :all, :params => {:base_system => "sle11_sp1"}
36
24
  assert_equal 48, res.size
37
- res = StudioApi::Rpm.find RPM_ID
25
+
26
+ register_fake_response_from_file :get, "/api/rpms/#{@rpm_id}",
27
+ 'rpm.xml'
28
+ res = StudioApi::Rpm.find @rpm_id
38
29
  assert "false", res.archive
39
30
  end
40
31
 
41
32
  def test_delete
42
- rpm = StudioApi::Rpm.find RPM_ID
33
+ register_fake_response_from_file :get, "/api/rpms/#{@rpm_id}",
34
+ 'rpm.xml'
35
+ register_fake_response_from_file :delete, "/api/rpms/#{@rpm_id}",
36
+ 'rpm.xml'
37
+ rpm = StudioApi::Rpm.find @rpm_id
43
38
  assert rpm.destroy
44
- assert StudioApi::Rpm.delete RPM_ID
39
+ assert StudioApi::Rpm.delete @rpm_id
45
40
  end
46
41
 
47
- TEST_STRING = "My lovely testing string\n Doodla da da da nicht"
48
42
  def test_download
49
- StudioApi::GenericRequest.any_instance.stubs(:get).with("/rpms/#{RPM_ID}/data").returns(TEST_STRING)
50
- assert_equal TEST_STRING, StudioApi::Rpm.new(:id=> RPM_ID).content
43
+ register_fake_response :get, "/api/rpms/#{@rpm_id}/data", @rpm_data
44
+ assert_equal @rpm_data, StudioApi::Rpm.new(:id=> @rpm_id).content
51
45
  end
52
46
 
53
- def test_upload
54
- rpm_out = respond_load "rpm.xml"
55
- StudioApi::GenericRequest.any_instance.stubs(:post).returns(rpm_out)
56
- assert StudioApi::Rpm.upload(TEST_STRING, "SLE11")
57
- end
47
+ def test_upload
48
+ register_fake_response_from_file :post, "/api/rpms?base_system=SLE11",
49
+ 'rpm.xml'
50
+ assert StudioApi::Rpm.upload(@rpm_data, "SLE11")
51
+ end
58
52
 
59
53
  end