1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[openstack] Update mocks for login and identity request #get_user_by_id

Signed-off-by: Nelvin Driz <nelvindriz@live.com>
This commit is contained in:
Nelvin Driz 2012-03-19 13:52:58 +08:00
parent 685eb85c1b
commit 92523f763a
4 changed files with 70 additions and 1 deletions

View file

@ -179,6 +179,18 @@ module Fog
def initialize(options={})
@openstack_username = options[:openstack_username]
@data ||= { :users => {}}
unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
id = Fog::Mock.random_numbers(6).to_s
@data[:users][id] = {
'id' => id,
'name' => options[:openstack_username],
'email' => "#{options[:openstack_username]}@mock.com",
'tenantId' => Fog::Mock.random_numbers(6).to_s,
'enabled' => true
}
end
end
def data
@ -189,6 +201,13 @@ module Fog
self.class.data.delete(@openstack_username)
end
def credentials
{ :provider => 'openstack',
:openstack_auth_url => @openstack_auth_uri.to_s,
:openstack_auth_token => @auth_token,
:openstack_management_url => @openstack_management_url,
:openstack_identity_endpoint => @openstack_identity_public_endpoint }
end
end
class Real

View file

@ -69,6 +69,18 @@ module Fog
def initialize(options={})
require 'multi_json'
@openstack_username = options[:openstack_username]
@data ||= { :users => {}}
unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
id = Fog::Mock.random_numbers(6).to_s
@data[:users][id] = {
'id' => id,
'name' => options[:openstack_username],
'email' => "#{options[:openstack_username]}@mock.com",
'tenantId' => Fog::Mock.random_numbers(6).to_s,
'enabled' => true
}
end
end
def data
@ -78,6 +90,14 @@ module Fog
def reset_data
self.class.data.delete(@openstack_username)
end
def credentials
{ :provider => 'openstack',
:openstack_auth_url => @openstack_auth_uri.to_s,
:openstack_auth_token => @auth_token,
:openstack_management_url => @openstack_management_url,
:openstack_current_user_id => @openstack_current_user_id}
end
end
class Real

View file

@ -47,6 +47,18 @@ module Fog
def initialize(options={})
require 'multi_json'
@openstack_username = options[:openstack_username]
@data ||= { :users => {} }
unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
id = Fog::Mock.random_numbers(6).to_s
@data[:users][id] = {
'id' => id,
'name' => options[:openstack_username],
'email' => "#{options[:openstack_username]}@mock.com",
'tenantId' => Fog::Mock.random_numbers(6).to_s,
'enabled' => true
}
end
end
def data
@ -56,6 +68,13 @@ module Fog
def reset_data
self.class.data.delete(@openstack_username)
end
def credentials
{ :provider => 'openstack',
:openstack_auth_url => @openstack_auth_uri.to_s,
:openstack_auth_token => @auth_token,
:openstack_management_url => @openstack_management_url }
end
end
class Real

View file

@ -14,9 +14,20 @@ module Fog
end
class Mock
def get_user_by_id(user_id)
response = Excon::Response.new
response.status = 200
existing_user = self.data[:users].find do |u|
u[0] == user_id || u[1]['name'] == 'mock'
end
existing_user = existing_user[1] if existing_user
response.body = {
'user' => existing_user || create_user('mock', 'mock', 'mock@email.com').body['user']
}
response
end
end
end
end