mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
OpenStack: get identity tests passing in real mode
Updates to the OpenStack identity tests to they pass in both real and mock modes. Also, fixes an issue in the delete_user_role request where it was expecting 200 instead of 204 (which seems to match the spec and implementation).
This commit is contained in:
parent
a67198e885
commit
65a90fd655
7 changed files with 51 additions and 24 deletions
|
@ -37,7 +37,7 @@ module Fog
|
|||
when :add
|
||||
service.create_user_role(tenant_id, user_id, id).status == 200
|
||||
when :remove
|
||||
service.delete_user_role(tenant_id, user_id, id).status == 200
|
||||
service.delete_user_role(tenant_id, user_id, id).status == 204
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ module Fog
|
|||
|
||||
def delete_user_role(tenant_id, user_id, role_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => "/tenants/#{tenant_id}/users/#{user_id}/roles/OS-KSADM/#{role_id}"
|
||||
)
|
||||
|
@ -16,7 +16,7 @@ module Fog
|
|||
class Mock
|
||||
def delete_user_role(tenant_id, user_id, role_id)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.status = 204
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,9 +18,9 @@ module Fog
|
|||
def get_user_by_name(name)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
user = self.data[:users].values.select {|user| user['name'] == name}[0]
|
||||
response.body = {
|
||||
'users' => self.data[:users].values
|
||||
'user' => user
|
||||
}
|
||||
response
|
||||
end
|
||||
|
|
|
@ -7,12 +7,15 @@ Shindo.tests('Fog::Identity[:openstack] | EC2 credential requests', ['openstack'
|
|||
'user_id' => String,
|
||||
}
|
||||
|
||||
@user_id = OpenStack::Identity.get_user_id
|
||||
@tenant_id = OpenStack::Identity.get_tenant_id
|
||||
|
||||
tests('success') do
|
||||
tests('#create_ec2_credential').
|
||||
formats({'credential' => @credential_format}) do
|
||||
response =
|
||||
Fog::Identity[:openstack].
|
||||
create_ec2_credential('user_id', 'tenant_id')
|
||||
create_ec2_credential(@user_id, @tenant_id)
|
||||
|
||||
@ec2_credential = response.body['credential']
|
||||
|
||||
|
@ -22,18 +25,18 @@ Shindo.tests('Fog::Identity[:openstack] | EC2 credential requests', ['openstack'
|
|||
tests('#get_ec2_credential').
|
||||
formats({'credential' => @credential_format}) do
|
||||
Fog::Identity[:openstack].
|
||||
get_ec2_credential('user_id', @ec2_credential['access']).body
|
||||
get_ec2_credential(@user_id, @ec2_credential['access']).body
|
||||
end
|
||||
|
||||
tests('#list_ec2_credentials').
|
||||
formats({'credentials' => [@credential_format]}) do
|
||||
Fog::Identity[:openstack].
|
||||
list_ec2_credentials('user_id').body
|
||||
list_ec2_credentials(@user_id).body
|
||||
end
|
||||
|
||||
tests('#delete_ec2_credential').succeeds do
|
||||
Fog::Identity[:openstack].
|
||||
delete_ec2_credential('user_id', @ec2_credential['access'])
|
||||
delete_ec2_credential(@user_id, @ec2_credential['access'])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
17
tests/openstack/requests/identity/helper.rb
Normal file
17
tests/openstack/requests/identity/helper.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class OpenStack
|
||||
|
||||
module Identity
|
||||
|
||||
def self.get_tenant_id
|
||||
identity = Fog::Identity[:openstack]
|
||||
ENV['OPENSTACK_TENANT_NAME'] || identity.list_tenants.body['tenants'].first['id']
|
||||
end
|
||||
|
||||
def self.get_user_id
|
||||
identity = Fog::Identity[:openstack]
|
||||
ENV['OPENSTACK_USER_ID'] || identity.list_users.body['users'].first['id']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -13,6 +13,10 @@ Shindo.tests('Fog::Identity[:openstack] | tenant requests', ['openstack']) do
|
|||
'name' => String
|
||||
}
|
||||
|
||||
@tenant_name = Fog::Mock.random_hex(64)
|
||||
@tenant_name_update = Fog::Mock.random_hex(64)
|
||||
@tenant_name_update2 = Fog::Mock.random_hex(64)
|
||||
|
||||
tests('success') do
|
||||
tests('#list_tenants').formats({'tenants' => [@tenant_format], 'tenants_links' => []}) do
|
||||
Fog::Identity[:openstack].list_tenants.body
|
||||
|
@ -20,34 +24,33 @@ Shindo.tests('Fog::Identity[:openstack] | tenant requests', ['openstack']) do
|
|||
|
||||
tests('#list_roles_for_user_on_tenant(0,1)').
|
||||
formats({'roles' => [@role_format]}) do
|
||||
user = Fog::Identity[:openstack].create_user("testuser", "passw", "e@mail.co", "us3r1d").body['user']
|
||||
|
||||
openstack = Fog::Identity[:openstack]
|
||||
openstack.list_roles_for_user_on_tenant(
|
||||
openstack.current_tenant['id'], user['id']).body
|
||||
openstack.current_tenant['id'], OpenStack::Identity.get_user_id).body
|
||||
end
|
||||
|
||||
tests('#create_tenant').formats({'tenant' => @tenant_format}) do
|
||||
@instance = Fog::Identity[:openstack].create_tenant('name' => 'test').body
|
||||
@tenant = Fog::Identity[:openstack].create_tenant('name' => @tenant_name).body
|
||||
end
|
||||
|
||||
tests('#get_tenant').formats({'tenant' => @tenant_format}) do
|
||||
Fog::Identity[:openstack].get_tenant(@instance['tenant']['id']).body
|
||||
Fog::Identity[:openstack].get_tenant(@tenant['tenant']['id']).body
|
||||
end
|
||||
|
||||
tests('#update_tenant check format').formats({'tenant' => @tenant_format}) do
|
||||
@instance = Fog::Identity[:openstack].update_tenant(
|
||||
@instance['tenant']['id'], 'name' => 'test2').body
|
||||
@tenant = Fog::Identity[:openstack].update_tenant(
|
||||
@tenant['tenant']['id'], 'name' => @tenant_name_update).body
|
||||
end
|
||||
|
||||
tests('#update_tenant update name').succeeds do
|
||||
@instance = Fog::Identity[:openstack].update_tenant(
|
||||
@instance['tenant']['id'], 'name' => 'test3').body
|
||||
@instance['tenant']['name'] == 'test3'
|
||||
@tenant = Fog::Identity[:openstack].update_tenant(
|
||||
@tenant['tenant']['id'], 'name' => @tenant_name_update2).body
|
||||
@tenant['tenant']['name'] == @tenant_name_update2
|
||||
end
|
||||
|
||||
tests('#delete_tenant').succeeds do
|
||||
Fog::Identity[:openstack].delete_tenant(@instance['tenant']['id'])
|
||||
Fog::Identity[:openstack].delete_tenant(@tenant['tenant']['id'])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,8 +9,12 @@ Shindo.tests('Fog::Identity[:openstack] | user requests', ['openstack']) do
|
|||
}
|
||||
|
||||
tests('success') do
|
||||
tests('#create_user("Onamae", "spoof", "user@email.com", "t3n4nt1d", true)').formats(@user_format, false) do
|
||||
@user = Fog::Identity[:openstack].create_user("Onamae", "spoof", "morph@example.com", "m0rPh1d").body['user']
|
||||
|
||||
@user_name = Fog::Mock.random_hex(64)
|
||||
@user_name_update = Fog::Mock.random_hex(64)
|
||||
|
||||
tests("#create_user('#{@user_name}', 'mypassword', 'morph@example.com', 't3n4nt1d', true)").formats(@user_format, false) do
|
||||
@user = Fog::Identity[:openstack].create_user(@user_name, "mypassword", "morph@example.com", OpenStack::Identity.get_tenant_id).body['user']
|
||||
end
|
||||
|
||||
tests('#list_users').formats({'users' => [@user_format]}) do
|
||||
|
@ -21,12 +25,12 @@ Shindo.tests('Fog::Identity[:openstack] | user requests', ['openstack']) do
|
|||
Fog::Identity[:openstack].get_user_by_id(@user['id']).body['user']
|
||||
end
|
||||
|
||||
tests('#get_user_by_name').formats({'users' => [@user_format]}) do
|
||||
Fog::Identity[:openstack].get_user_by_name(@user['name']).body
|
||||
tests('#get_user_by_name').formats(@user_format) do
|
||||
Fog::Identity[:openstack].get_user_by_name(@user['name']).body['user']
|
||||
end
|
||||
|
||||
tests("#update_user(#{@user['id']}, :name => 'fogupdateduser')").succeeds do
|
||||
Fog::Identity[:openstack].update_user(@user['id'], :name => 'fogupdateduser', :email => 'fog@test.com')
|
||||
Fog::Identity[:openstack].update_user(@user['id'], :name => @user_name_update, :email => 'fog@test.com')
|
||||
end
|
||||
|
||||
tests("#delete_user(#{@user['id']})").succeeds do
|
||||
|
|
Loading…
Add table
Reference in a new issue