mirror of
				https://github.com/fog/fog.git
				synced 2022-11-09 13:51:43 -05:00 
			
		
		
		
	[brightbox] Tests for remaining API requests
* Request tests for accounts, api_clients, cloud_ips, images, interfaces, server types, user and zones * Added 'ready?' methods to CloudIp and Image models * Reworked brightbox helper to include Format patterns for all of the * Added "hack" to allow select objects to be one class OR NilClass for fields that may be a JSON string or null if unset * Some tests are not enabled (commented out) because they need manual steps (such as uploading Image to your account before registration)
This commit is contained in:
		
							parent
							
								
									a327b3446c
								
							
						
					
					
						commit
						6500fa46bf
					
				
					 12 changed files with 612 additions and 63 deletions
				
			
		
							
								
								
									
										29
									
								
								tests/brightbox/requests/compute/account_tests.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								tests/brightbox/requests/compute/account_tests.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
Shindo.tests('Brightbox::Compute | account requests', ['brightbox']) do
 | 
			
		||||
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    tests("#get_account()").formats(Brightbox::Compute::Formats::Full::ACCOUNT) do
 | 
			
		||||
      Brightbox[:compute].get_account()
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    original_name = Brightbox[:compute].get_account["name"]
 | 
			
		||||
    update_args = {:name => "New name from Fog test"}
 | 
			
		||||
    tests("#update_account(#{update_args.inspect})").formats(Brightbox::Compute::Formats::Full::ACCOUNT) do
 | 
			
		||||
      Brightbox[:compute].update_account(update_args)
 | 
			
		||||
    end
 | 
			
		||||
    Brightbox[:compute].update_account(:name => original_name)
 | 
			
		||||
 | 
			
		||||
    tests("#reset_ftp_password_account()").formats(Brightbox::Compute::Formats::Full::ACCOUNT) do
 | 
			
		||||
      Brightbox[:compute].reset_ftp_password_account()
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  tests('failure') do
 | 
			
		||||
 | 
			
		||||
    tests("#update_account()").returns(nil) do
 | 
			
		||||
      Brightbox[:compute].update_account()
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										41
									
								
								tests/brightbox/requests/compute/api_client_tests.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								tests/brightbox/requests/compute/api_client_tests.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
Shindo.tests('Brightbox::Compute | api client requests', ['brightbox']) do
 | 
			
		||||
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    create_options = {:name => "Name from Fog test (#{Time.now.to_i})", :description => "Description from Fog test"}
 | 
			
		||||
    tests("#create_api_client(#{create_options.inspect})").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do
 | 
			
		||||
      data = Brightbox[:compute].create_api_client(create_options)
 | 
			
		||||
      @api_client_id = data["id"]
 | 
			
		||||
      data
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#list_api_clients()").formats(Brightbox::Compute::Formats::Collection::API_CLIENTS) do
 | 
			
		||||
      Brightbox[:compute].list_api_clients()
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_api_client('#{@api_client_id}')").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do
 | 
			
		||||
      Brightbox[:compute].get_api_client(@api_client_id)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#update_api_client('#{@api_client_id}')").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do
 | 
			
		||||
      Brightbox[:compute].update_api_client(@api_client_id, :name => "New name from Fog test")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#destroy_api_client('#{@api_client_id}')").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do
 | 
			
		||||
      Brightbox[:compute].destroy_api_client(@api_client_id)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  tests('failure') do
 | 
			
		||||
 | 
			
		||||
    tests("#get_api_client('cli-00000')").raises(Excon::Errors::NotFound) do
 | 
			
		||||
      Brightbox[:compute].get_api_client('cli-00000')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_api_client()").raises(ArgumentError) do
 | 
			
		||||
      Brightbox[:compute].get_api_client()
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										49
									
								
								tests/brightbox/requests/compute/cloud_ip_tests.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								tests/brightbox/requests/compute/cloud_ip_tests.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,49 @@
 | 
			
		|||
Shindo.tests('Brightbox::Compute | cloud ip requests', ['brightbox']) do
 | 
			
		||||
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    tests("#create_cloud_ip()").formats(Brightbox::Compute::Formats::Full::CLOUD_IP) do
 | 
			
		||||
      data = Brightbox[:compute].create_cloud_ip()
 | 
			
		||||
      @cloud_ip_id = data["id"]
 | 
			
		||||
      data
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#list_cloud_ips()").formats(Brightbox::Compute::Formats::Collection::CLOUD_IPS) do
 | 
			
		||||
      Brightbox[:compute].list_cloud_ips()
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_cloud_ip('#{@cloud_ip_id}')").formats(Brightbox::Compute::Formats::Full::CLOUD_IP) do
 | 
			
		||||
      Brightbox[:compute].get_cloud_ip(@cloud_ip_id)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    server = Brightbox[:compute].servers.first
 | 
			
		||||
    interface_id = server.interfaces.first["id"]
 | 
			
		||||
    map_options = {:interface => interface_id}
 | 
			
		||||
    tests("#map_cloud_ip('#{@cloud_ip_id}', #{map_options.inspect})").formats(Brightbox::Compute::Formats::Full::CLOUD_IP) do
 | 
			
		||||
      Brightbox[:compute].map_cloud_ip(@cloud_ip_id, map_options)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    Brightbox[:compute].cloud_ips.get(@cloud_ip_id).wait_for { mapped? }
 | 
			
		||||
 | 
			
		||||
    tests("#unmap_cloud_ip('#{@cloud_ip_id}')").formats(Brightbox::Compute::Formats::Full::CLOUD_IP) do
 | 
			
		||||
      Brightbox[:compute].unmap_cloud_ip(@cloud_ip_id)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#destroy_cloud_ip('#{@cloud_ip_id}')").formats(Brightbox::Compute::Formats::Full::CLOUD_IP) do
 | 
			
		||||
      Brightbox[:compute].destroy_cloud_ip(@cloud_ip_id)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  tests('failure') do
 | 
			
		||||
 | 
			
		||||
    tests("#get_cloud_ip('cip-00000')").raises(Excon::Errors::NotFound) do
 | 
			
		||||
      Brightbox[:compute].get_cloud_ip('cip-00000')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_cloud_ip()").raises(ArgumentError) do
 | 
			
		||||
      Brightbox[:compute].get_cloud_ip()
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										52
									
								
								tests/brightbox/requests/compute/image_tests.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								tests/brightbox/requests/compute/image_tests.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,52 @@
 | 
			
		|||
Shindo.tests('Brightbox::Compute | image requests', ['brightbox']) do
 | 
			
		||||
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    ## Difficult to test without having uploaded an Image to your account to register
 | 
			
		||||
    # creation_options = {
 | 
			
		||||
    #   "arch" => "i686",
 | 
			
		||||
    #   "source" => "fnord"
 | 
			
		||||
    # }
 | 
			
		||||
    # tests("#create_image(#{creation_options.inspect})").formats(Brightbox::Compute::Formats::Full::IMAGE) do
 | 
			
		||||
    #   data = Brightbox[:compute].create_image(creation_options)
 | 
			
		||||
    #   @image_id = data["id"]
 | 
			
		||||
    #   data
 | 
			
		||||
    # end
 | 
			
		||||
 | 
			
		||||
    # Brightbox[:compute].images.get(@image_id).wait_for { ready? }
 | 
			
		||||
 | 
			
		||||
    tests("#list_images()").formats(Brightbox::Compute::Formats::Collection::IMAGES) do
 | 
			
		||||
      data = Brightbox[:compute].list_images()
 | 
			
		||||
      @image_id = data.first["id"]
 | 
			
		||||
      data
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_image('#{@image_id}')").formats(Brightbox::Compute::Formats::Full::IMAGE) do
 | 
			
		||||
      Brightbox[:compute].get_image(@image_id)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    ## Until Image creation can be automated, we shouldn't be updating Images randomly
 | 
			
		||||
    # update_options = {}
 | 
			
		||||
    # tests("#update_image('#{@image_id}', #{update_options.inspect})").formats(Brightbox::Compute::Formats::Full::IMAGE) do
 | 
			
		||||
    #   Brightbox[:compute].update_image(@image_id, :name => "New name from Fog test")
 | 
			
		||||
    # end
 | 
			
		||||
 | 
			
		||||
    ## Same as other tests - can't be deleting them unless part of the test run
 | 
			
		||||
    # tests("#destroy_server('#{@image_id}')").formats(Brightbox::Compute::Formats::Full::IMAGE) do
 | 
			
		||||
    #   Brightbox[:compute].destroy_image(@image_id)
 | 
			
		||||
    # end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  tests('failure') do
 | 
			
		||||
 | 
			
		||||
    tests("#get_image('img-00000')").raises(Excon::Errors::NotFound) do
 | 
			
		||||
      Brightbox[:compute].get_image('img-00000')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_image()").raises(ArgumentError) do
 | 
			
		||||
      Brightbox[:compute].get_image()
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										24
									
								
								tests/brightbox/requests/compute/interface_tests.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								tests/brightbox/requests/compute/interface_tests.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
Shindo.tests('Brightbox::Compute | interface requests', ['brightbox']) do
 | 
			
		||||
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    server = Brightbox[:compute].servers.first
 | 
			
		||||
    @interface_id = server.interfaces.first["id"]
 | 
			
		||||
    tests("#get_interface('#{@interface_id}')").formats(Brightbox::Compute::Formats::Full::INTERFACE) do
 | 
			
		||||
      Brightbox[:compute].get_interface(@interface_id)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  tests('failure') do
 | 
			
		||||
 | 
			
		||||
    tests("#get_interface('int-00000')").raises(Excon::Errors::Forbidden) do
 | 
			
		||||
      Brightbox[:compute].get_interface('int-00000')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_interface()").raises(ArgumentError) do
 | 
			
		||||
      Brightbox[:compute].get_interface()
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -13,10 +13,9 @@ Shindo.tests('Brightbox::Compute | server requests', ['brightbox']) do
 | 
			
		|||
 | 
			
		||||
    Brightbox[:compute].servers.get(server_id).wait_for { ready? }
 | 
			
		||||
 | 
			
		||||
    # Collection of Servers fails to match since deleted_at can be a String OR a NilClass
 | 
			
		||||
    # tests("#list_servers()").formats(Brightbox::Compute::Formats::Collection::SERVERS) do
 | 
			
		||||
    #   Brightbox[:compute].list_servers()
 | 
			
		||||
    # end
 | 
			
		||||
    tests("#list_servers()").formats(Brightbox::Compute::Formats::Collection::SERVERS) do
 | 
			
		||||
      Brightbox[:compute].list_servers()
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_server('#{server_id}')").formats(Brightbox::Compute::Formats::Full::SERVER) do
 | 
			
		||||
      Brightbox[:compute].get_server(server_id)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										28
									
								
								tests/brightbox/requests/compute/server_type_tests.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								tests/brightbox/requests/compute/server_type_tests.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
Shindo.tests('Brightbox::Compute | server type requests', ['brightbox']) do
 | 
			
		||||
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    tests("#list_server_types()").formats(Brightbox::Compute::Formats::Collection::SERVER_TYPES) do
 | 
			
		||||
      data = Brightbox[:compute].list_server_types()
 | 
			
		||||
      @server_type_id = data.first["id"]
 | 
			
		||||
      data
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_server_type('#{@server_type_id}')").formats(Brightbox::Compute::Formats::Full::SERVER_TYPE) do
 | 
			
		||||
      Brightbox[:compute].get_server_type(@server_type_id)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  tests('failure') do
 | 
			
		||||
 | 
			
		||||
    tests("#get_server_type('typ-00000')").raises(Excon::Errors::NotFound) do
 | 
			
		||||
      Brightbox[:compute].get_server_type('typ-00000')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_server()").raises(ArgumentError) do
 | 
			
		||||
      Brightbox[:compute].get_server_type()
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										33
									
								
								tests/brightbox/requests/compute/user_tests.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								tests/brightbox/requests/compute/user_tests.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
Shindo.tests('Brightbox::Compute | user requests', ['brightbox']) do
 | 
			
		||||
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    tests("#list_users()").formats(Brightbox::Compute::Formats::Collection::USERS) do
 | 
			
		||||
      data = Brightbox[:compute].list_users()
 | 
			
		||||
      @user_id = data.first["id"]
 | 
			
		||||
      data
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_user('#{@user_id}')").formats(Brightbox::Compute::Formats::Full::USER) do
 | 
			
		||||
      data = Brightbox[:compute].get_user(@user_id)
 | 
			
		||||
      @original_name = data["name"]
 | 
			
		||||
      data
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    update_options = { :name => "New name from Fog" }
 | 
			
		||||
    tests("#update_user('#{@user_id}', #{update_options.inspect})").formats(Brightbox::Compute::Formats::Full::USER) do
 | 
			
		||||
      Brightbox[:compute].update_user(@user_id, update_options)
 | 
			
		||||
    end
 | 
			
		||||
    Brightbox[:compute].update_user(@user_id, :name => @original_name)
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  tests('failure') do
 | 
			
		||||
 | 
			
		||||
    tests("#update_user()").raises(ArgumentError) do
 | 
			
		||||
      Brightbox[:compute].update_user()
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										28
									
								
								tests/brightbox/requests/compute/zone_tests.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								tests/brightbox/requests/compute/zone_tests.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
Shindo.tests('Brightbox::Compute | zone requests', ['brightbox']) do
 | 
			
		||||
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    tests("#list_zones()").formats(Brightbox::Compute::Formats::Collection::ZONES) do
 | 
			
		||||
      data = Brightbox[:compute].list_zones()
 | 
			
		||||
      @zone_id = data.first["id"]
 | 
			
		||||
      data
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_zone('#{@zone_id}')").formats(Brightbox::Compute::Formats::Full::ZONE) do
 | 
			
		||||
      Brightbox[:compute].get_zone(@zone_id)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  tests('failure') do
 | 
			
		||||
 | 
			
		||||
    tests("#get_zone('zon-00000')").raises(Excon::Errors::NotFound) do
 | 
			
		||||
      Brightbox[:compute].get_zone('zon-00000')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tests("#get_zone()").raises(ArgumentError) do
 | 
			
		||||
      Brightbox[:compute].get_zone()
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue