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

[openstack|identity] Update users collections and model

This commit is contained in:
Alvin Garcia 2012-03-09 17:28:32 +08:00 committed by Nelvin Driz
parent a1ecf11e25
commit 040cd20021
3 changed files with 45 additions and 1 deletions

View file

@ -9,7 +9,7 @@ module Fog
attribute :email
attribute :enabled
attribute :name
attribute :tenantId, :aliases => 'tenant_id'
attribute :tenant_id, :aliases => 'tenantId'
attribute :password
attr_accessor :email, :name, :tenant_id, :enabled, :password

View file

@ -10,6 +10,17 @@ module Fog
def all
load(connection.list_users.body['users'])
end
def find_by_id(id)
self.find {|user| user.id == id} ||
Fog::Identity::OpenStack::User.new(
connection.get_user_by_id(id).body['user'])
end
def destroy(id)
user = self.find_by_id(id)
user.destroy
end
end # class Users
end # class OpenStack
end # module Identity

View file

@ -0,0 +1,33 @@
Shindo.tests("Fog::Identity[:openstack] | users", ['openstack']) do
tenant_id = Fog::Identity[:openstack].list_tenants.body['tenants'].first['id']
@instance = Fog::Identity[:openstack].users.create({
:name => 'foobar',
:email => 'foo@bar.com',
:tenant_id => tenant_id,
:password => 'spoof',
:enabled => true
})
tests('success') do
tests('#find_by_id').succeeds do
user = Fog::Identity[:openstack].users.find_by_id(@instance.id)
user.id == @instance.id
end
tests('#destroy').succeeds do
Fog::Identity[:openstack].users.destroy(@instance.id)
end
end
tests('fails') do
pending if Fog.mocking?
tests('#find_by_id').raises(Fog::Identity::OpenStack::NotFound) do
Fog::Identity[:openstack].users.find_by_id('fake')
end
tests('#destroy').raises(Fog::Identity::OpenStack::NotFound) do
Fog::Identity[:openstack].users.destroy('fake')
end
end
end