From 92523f763a0369bec29179fb6d4b5af17435fc42 Mon Sep 17 00:00:00 2001 From: Nelvin Driz Date: Mon, 19 Mar 2012 13:52:58 +0800 Subject: [PATCH] [openstack] Update mocks for login and identity request #get_user_by_id Signed-off-by: Nelvin Driz --- lib/fog/openstack/compute.rb | 19 ++++++++++++++++++ lib/fog/openstack/identity.rb | 20 +++++++++++++++++++ lib/fog/openstack/image.rb | 19 ++++++++++++++++++ .../requests/identity/get_user_by_id.rb | 13 +++++++++++- 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/lib/fog/openstack/compute.rb b/lib/fog/openstack/compute.rb index 7ab0d926a..a06b01d9b 100644 --- a/lib/fog/openstack/compute.rb +++ b/lib/fog/openstack/compute.rb @@ -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 diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index d77ec32e2..fa08fbda6 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -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 diff --git a/lib/fog/openstack/image.rb b/lib/fog/openstack/image.rb index b5380389d..a156c4ca9 100644 --- a/lib/fog/openstack/image.rb +++ b/lib/fog/openstack/image.rb @@ -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 diff --git a/lib/fog/openstack/requests/identity/get_user_by_id.rb b/lib/fog/openstack/requests/identity/get_user_by_id.rb index 8aaa4ce5b..e00f3086d 100644 --- a/lib/fog/openstack/requests/identity/get_user_by_id.rb +++ b/lib/fog/openstack/requests/identity/get_user_by_id.rb @@ -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