mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Rackspace identity_tests now pass in mocking mode.
Implemented a mock for the #list_tenants request.
This commit is contained in:
parent
da64e0b2c6
commit
00ed428bdc
4 changed files with 50 additions and 24 deletions
|
@ -34,21 +34,16 @@ module Fog
|
|||
request :update_user
|
||||
request :delete_user
|
||||
|
||||
class Mock < Fog::Rackspace::Service
|
||||
attr_reader :service_catalog
|
||||
|
||||
def initialize(options={})
|
||||
end
|
||||
|
||||
def request
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
||||
class Real < Fog::Rackspace::Service
|
||||
module Common
|
||||
attr_reader :service_catalog, :auth_token
|
||||
|
||||
def initialize(options={})
|
||||
|
||||
def authenticate(options={})
|
||||
data = self.create_token(@rackspace_username, @rackspace_api_key).body
|
||||
@service_catalog = ServiceCatalog.from_response(self, data)
|
||||
@auth_token = data['access']['token']['id']
|
||||
end
|
||||
|
||||
def interpret_options(options)
|
||||
@rackspace_username = options[:rackspace_username]
|
||||
@rackspace_api_key = options[:rackspace_api_key]
|
||||
@rackspace_region = options[:rackspace_region]
|
||||
|
@ -61,15 +56,27 @@ module Fog
|
|||
@scheme = @uri.scheme
|
||||
@persistent = options[:persistent] || false
|
||||
@connection_options = options[:connection_options] || {}
|
||||
@connection = Fog::Connection.new(@uri.to_s, @persistent, @connection_options)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock < Fog::Rackspace::Service
|
||||
include Common
|
||||
|
||||
def initialize(options={})
|
||||
interpret_options(options)
|
||||
|
||||
authenticate
|
||||
end
|
||||
end
|
||||
|
||||
class Real < Fog::Rackspace::Service
|
||||
include Common
|
||||
|
||||
def authenticate(options={})
|
||||
data = self.create_token(@rackspace_username, @rackspace_api_key).body
|
||||
@service_catalog = ServiceCatalog.from_response(self, data)
|
||||
@auth_token = data['access']['token']['id']
|
||||
def initialize(options={})
|
||||
interpret_options(options)
|
||||
@connection = Fog::Connection.new(@uri.to_s, @persistent, @connection_options)
|
||||
|
||||
authenticate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def create_token(username, api_key)
|
||||
unless username == 'baduser'
|
||||
unless username == 'baduser' || api_key == 'bad_key'
|
||||
compute_tenant = Fog::Mock.random_numbers(6)
|
||||
object_tenant = generate_object_tenant
|
||||
|
||||
|
|
|
@ -17,6 +17,29 @@ module Fog
|
|||
response
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_tenants
|
||||
response = Excon::Response.new
|
||||
response.status = [200, 203][rand(1)]
|
||||
response.body = {
|
||||
"tenants" => [
|
||||
{
|
||||
"id" => Fog::Mock.random_numbers(6),
|
||||
"name" => "Enabled tenant",
|
||||
"enabled" => true
|
||||
},
|
||||
{
|
||||
"id" => Fog::Mock.random_numbers(6),
|
||||
"name" => "Disabled tenant",
|
||||
"enabled" => false
|
||||
},
|
||||
],
|
||||
"tenants_links" => []
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
Shindo.tests('Fog::Rackspace::Identity', ['rackspace']) do
|
||||
|
||||
tests('current authentication') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
tests('variables populated').returns(200) do
|
||||
@service = Fog::Rackspace::Identity.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :connection_options => {:ssl_verify_peer => true}
|
||||
returns(true, "auth token populated") { !@service.auth_token.nil? }
|
||||
|
@ -14,8 +12,6 @@ Shindo.tests('Fog::Rackspace::Identity', ['rackspace']) do
|
|||
end
|
||||
|
||||
tests('reauthentication') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
tests('should reauth with valid credentials') do
|
||||
@service = Fog::Rackspace::Identity.new :rackspace_region => :ord
|
||||
returns(true, "auth token populated") { !@service.auth_token.nil? }
|
||||
|
|
Loading…
Reference in a new issue