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

[openstack|identity] fixes for mocks

This commit is contained in:
geemus 2012-05-28 16:45:22 -05:00
parent 36115c60ef
commit 230c61dad5
8 changed files with 42 additions and 45 deletions

View file

@ -70,10 +70,9 @@ module Fog
def initialize(options={})
@openstack_username = options[:openstack_username]
@data ||= { :users => {}}
unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
unless self.data[:users].values.detect {|user| user['name'] == @openstack_username}
id = Fog::Mock.random_numbers(6).to_s
@data[:users][id] = {
self.data[:users][id] = {
'id' => id,
'name' => options[:openstack_username],
'email' => "#{options[:openstack_username]}@mock.com",

View file

@ -20,15 +20,15 @@ module Fog
class Mock
def create_role(name)
response = Excon::Response.new
response.status = 202
data = {
'id' => Fog::Mock.random_numbers(6).to_s,
'name' => name
}
self.data[:roles][data['id']] = data
response.body = { 'role' => data }
response
Excon::Response.new(
:body => { 'role' => data },
:status => 202
)
end
end

View file

@ -15,9 +15,10 @@ module Fog
class Mock
def create_user_role(tenant_id, user_id, role_id)
response = Excon::Response.new
response.status = 200
response
Excon::Response.new(
:body => { 'role' => self.data[:roles][role_id] },
:status => 200
)
end
end
end

View file

@ -16,10 +16,10 @@ module Fog
class Mock
def list_roles
response = Excon::Response.new
response.status = 200
response.body = { 'roles' => self.data[:roles] }
response
Excon::Response.new(
:body => { 'roles' => self.data[:roles] },
:status => 200
)
end
end

View file

@ -13,12 +13,10 @@ module Fog
class Mock
def list_roles_for_user_on_tenant(tenant_id, user_id)
response = Excon::Response.new
response.status = 200
response.body = {
'roles' => self.data[:roles]
}
response
Excon::Response.new(
:body => { 'roles' => self.data[:roles] },
:status => 200
)
end # def list_roles_for_user_on_tenant
end # class Mock
end # class OpenStack

View file

@ -18,25 +18,25 @@ module Fog
class Mock
def list_tenants
response = Excon::Response.new
response.status = [200, 204][rand(1)]
response.body = {
'tenants' => [
{'id' => '1',
'description' => 'Has access to everything',
'enabled' => true,
'name' => 'admin'},
{'id' => '2',
'description' => 'Normal tenant',
'enabled' => true,
'name' => 'default'},
{'id' => '3',
'description' => 'Disabled tenant',
'enabled' => false,
'name' => 'disabled'}
]
}
response
Excon::Response.new(
:body => {
'tenants' => [
{'id' => '1',
'description' => 'Has access to everything',
'enabled' => true,
'name' => 'admin'},
{'id' => '2',
'description' => 'Normal tenant',
'enabled' => true,
'name' => 'default'},
{'id' => '3',
'description' => 'Disabled tenant',
'enabled' => false,
'name' => 'disabled'}
]
},
:status => [200, 204][rand(1)]
)
end # def list_tenants
end # class Mock
end # class OpenStack

View file

@ -14,10 +14,10 @@ module Fog
class Mock
def list_users(tenant_id = nil)
response = Excon::Response.new
response.status = 200
response.body = { 'users' => self.data[:users].values }
response
Excon::Response.new(
:body => { 'users' => self.data[:users].values },
:status => 200
)
end
end # class Mock
end # class OpenStack

View file

@ -19,11 +19,10 @@ module Fog
def update_user(user_id, options)
response = Excon::Response.new
if user = list_users.body['users'][user_id]
if user = self.data[:users][user_id]
if options['name']
user['name'] = options['name']
end
self.data[:users][data['id']] = user
response.status = 200
response
else