Skip to content

Commit

Permalink
Merge 09d274b into 67fadba
Browse files Browse the repository at this point in the history
  • Loading branch information
gildub committed May 25, 2016
2 parents 67fadba + 09d274b commit 7d4f9e0
Show file tree
Hide file tree
Showing 26 changed files with 591 additions and 521 deletions.
44 changes: 44 additions & 0 deletions test/models/identity/ec2_credential_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require "test_helper"

describe "Fog::Identity[:openstack] | ec2_credential" do
before do
identity = Fog::Identity[:openstack]
tenant_id = identity.list_tenants.body['tenants'].first['id']

@user = identity.users.find { |user| user.name == 'foobar' }
@user ||= identity.users.create(
:name => 'foobar',
:email => 'foo@bar.com',
:tenant_id => tenant_id,
:password => 'spoof',
:enabled => true
)

@ec2_credential = identity.ec2_credentials.create(
:user_id => @user.id,
:tenant_id => tenant_id
)
end

after do
@user.ec2_credentials.each do |ec2_credential|
ec2_credential.destroy
end

@user.destroy
end

describe "success" do
it "#destroy" do
@ec2_credential.destroy.must_equal(true)
end
end

describe "failure" do
it "#save" do
proc do
@ec2_credential.save
end.must_raise(Fog::Errors::Error)
end
end
end
60 changes: 60 additions & 0 deletions test/models/identity/ec2_credentials_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require "test_helper"

describe "Fog::Identity[:openstack] | ec2_credentials" do
before do
identity = Fog::Identity[:openstack]
tenant_id = identity.list_tenants.body['tenants'].first['id']

@user = identity.users.find { |user| user.name == 'foobar' }
@user ||= identity.users.create(
:name => 'foobar',
:email => 'foo@bar.com',
:tenant_id => tenant_id,
:password => 'spoof',
:enabled => true
)

@ec2_credential = identity.ec2_credentials.create(
:user_id => @user.id,
:tenant_id => tenant_id
)
end

after do
@user.ec2_credentials.each(&:destroy)
@user.destroy
end

describe "success" do
it "#find_by_access_key" do
ec2_credential =
@user.ec2_credentials.find_by_access_key(@ec2_credential.access)

ec2_credential.access.must_equal @ec2_credential.access
end

it "#create" do
@user.ec2_credentials.create.tenant_id.wont_be_empty
end

it "#destroy" do
@user.ec2_credentials.destroy(@ec2_credential.access).must_equal true
end
end

describe "fails" do
it "#find_by_access_key" do
skip if Fog.mocking?
proc do
@user.ec2_credentials.find_by_access_key('fake')
end.must_raise(Fog::Identity::OpenStack::NotFound)
end

it "#destroy" do
skip if Fog.mocking?
proc do
@user.ec2_credentials.destroy('fake')
end.must_raise(Fog::Identity::OpenStack::NotFound)
end
end
end
42 changes: 42 additions & 0 deletions test/models/identity/role_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "test_helper"

describe "Fog::Identity[:openstack] | role" do
before do
@identity = Fog::Identity[:openstack]
@instance = @identity.roles.new(
:name => 'Role Name',
:user_id => 1,
:role_id => 1
)
@tenant = @identity.tenants.create(:name => 'test_user')
@user = @identity.users.create(
:name => 'test_user',
:tenant_id => @tenant.id,
:password => 'spoof'
)
@instance_saved = @instance.save
end

describe "success" do
it "#save" do
@instance_saved.must_equal true
end

it "#add_to_user(@user.id, @tenant.id)" do
@instance.add_to_user(@user.id, @tenant.id).must_equal true
end

it "#remove_to_user(@user.id, @tenant.id)" do
@instance.remove_to_user(@user.id, @tenant.id).must_equal true
end

it "#destroy" do
@instance.destroy.must_equal(true)
end
end

after do
@user.destroy
@tenant.destroy
end
end
28 changes: 28 additions & 0 deletions test/models/identity/roles_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "test_helper"

describe "Fog::Identity[:openstack] | roles" do
before do
@identity = Fog::Identity[:openstack]

@tenant = @identity.tenants.create(:name => 'test_user')
@user = @identity.users.create(:name => 'test_user', :tenant_id => @tenant.id, :password => 'spoof')
@role = @identity.roles(:user => @user, :tenant => @tenant).create(:name => 'test_role')
@roles = @identity.roles(:user => @user, :tenant => @tenant)
end

describe "success" do
it "#all" do
@roles.all.must_be_kind_of Fog::Identity::OpenStack::V2::Roles
end

it "#get" do
@roles.get(@roles.first.id).body.wont_be_nil
end

after do
@role.destroy
@user.destroy
@tenant.destroy
end
end
end
41 changes: 41 additions & 0 deletions test/models/identity/tenant_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "test_helper"

describe "Fog::Identity[:openstack] | tenant" do
before do
@identity = Fog::Identity[:openstack]
end

describe "success" do
before do
@instance = @identity.tenants.first
end

it "#roles_for(0)" do
@instance.roles_for(0)
end

it "#users" do
instance = @identity.tenants.first
instance.users.count.wont_equal @identity.users.count
end
end

describe "CRUD" do
before do
@instance = @identity.tenants.create(:name => 'test')
end

it "#create" do
@instance.id.nil?.wont_be_nil
end

it "#update" do
@instance.update(:name => 'test2')
@instance.name.must_equal 'test2'
end

it "#destroy" do
@instance.destroy.must_equal true
end
end
end
37 changes: 37 additions & 0 deletions test/models/identity/tenants_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require "test_helper"

describe "Fog::Compute[:openstack] | tenants" do
before do
@identity = Fog::Identity[:openstack]
@instance = @identity.tenants.create(:name => 'test')
end

describe "success" do
it "#find_by_id" do
tenant = @identity.tenants.find_by_id(@instance.id)
tenant.id.must_equal @instance.id
end

it "#destroy" do
@identity.tenants.destroy(@instance.id).must_equal true
end
end

describe "failure" do
it "#find_by_id" do
skip if Fog.mocking?

proc do
@identity.tenants.find_by_id('fake')
end.must_raise(Fog::Identity::OpenStack::NotFound)
end

it "#destroy" do
skip if Fog.mocking?

proc do
@identity.tenants.destroy('fake')
end.must_raise(Fog::Identity::OpenStack::NotFound)
end
end
end
59 changes: 59 additions & 0 deletions test/models/identity/user_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require "test_helper"

describe "Fog::Identity[:openstack] | user" do
before do
@identity = Fog::Identity[:openstack]
@tenant_id = @identity.list_tenants.body['tenants'].first['id']
@instance = @identity.users.new(
:name => 'User Name',
:email => 'test@fog.com',
:tenant_id => @tenant_id,
:password => 'spoof',
:enabled => true
)
end

describe "success" do
before do
@instance_saved = @instance.save
end

it "#save" do
@instance_saved.must_equal true
end

it "#roles" do
@instance.roles.must_be_empty
end

it "#update" do
@instance.update(:name => 'updatename', :email => 'new@email.com').
must_equal true
end

it "#update_password" do
@instance.update_password('swordfish').must_equal true
end

it "#update_tenant" do
@instance.update_tenant(@tenant_id).must_equal true
end

it "#update_enabled" do
@instance.update_enabled(true).must_equal true
end

it "#destroy" do
@instance.destroy.must_equal true
end
end

describe "failure" do
it "#save" do
skip
proc do
@instance.save
end.must_raise(Fog::Errors::Error)
end
end
end
54 changes: 54 additions & 0 deletions test/models/identity/users_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require "test_helper"

describe "Fog::Identity[:openstack] | users" do
before do
@identity = Fog::Identity[:openstack]
tenant_id = @identity.list_tenants.body['tenants'].first['id']
@instance = @identity.users.create(
:name => 'foobar',
:email => 'foo@bar.com',
:tenant_id => tenant_id,
:password => 'spoof',
:enabled => true
)
end

describe "success" do
it "#find_by_id" do
user = @identity.users.find_by_id(@instance.id)
user.id.must_equal @instance.id
end

it "#find_by_name" do
user = @identity.users.find_by_name(@instance.name)
user.name.must_equal @instance.name
end

it "#destroy" do
@identity.users.destroy(@instance.id).must_equal true
end
end

describe "fails" do
it "#find_by_id" do
skip if Fog.mocking?
proc do
Fog::Identity[:openstack].users.find_by_id('fake')
end.must_raise(Fog::Identity::OpenStack::NotFound)
end

it "#find_by_name" do
skip if Fog.mocking?
proc do
Fog::Identity[:openstack].users.find_by_name('fake')
end.must_raise(Fog::Identity::OpenStack::NotFound)
end

it "#destroy" do
skip if Fog.mocking?
proc do
Fog::Identity[:openstack].users.destroy('fake')
end.must_raise(Fog::Identity::OpenStack::NotFound)
end
end
end

0 comments on commit 7d4f9e0

Please sign in to comment.