rhn_satellite 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +94 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/rhn_satellite.rb +25 -0
- data/lib/rhn_satellite/activation_key.rb +5 -0
- data/lib/rhn_satellite/api.rb +36 -0
- data/lib/rhn_satellite/channel.rb +5 -0
- data/lib/rhn_satellite/channel_access.rb +20 -0
- data/lib/rhn_satellite/channel_software.rb +20 -0
- data/lib/rhn_satellite/common/collection.rb +15 -0
- data/lib/rhn_satellite/common/debug.rb +35 -0
- data/lib/rhn_satellite/common/misc.rb +24 -0
- data/lib/rhn_satellite/connection/base.rb +25 -0
- data/lib/rhn_satellite/connection/handler.rb +116 -0
- data/lib/rhn_satellite/package.rb +15 -0
- data/lib/rhn_satellite/system.rb +83 -0
- data/lib/rhn_satellite/systemgroup.rb +34 -0
- data/rhn_satellite.gemspec +87 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/unit/rhn_satellite/activation_key_spec.rb +58 -0
- data/spec/unit/rhn_satellite/api_spec.rb +94 -0
- data/spec/unit/rhn_satellite/channel_access_spec.rb +61 -0
- data/spec/unit/rhn_satellite/channel_software_spec.rb +65 -0
- data/spec/unit/rhn_satellite/channel_spec.rb +58 -0
- data/spec/unit/rhn_satellite/common/debug_spec.rb +42 -0
- data/spec/unit/rhn_satellite/common/misc_spec.rb +33 -0
- data/spec/unit/rhn_satellite/connection/base_spec.rb +44 -0
- data/spec/unit/rhn_satellite/connection/handler_spec.rb +229 -0
- data/spec/unit/rhn_satellite/package_spec.rb +52 -0
- data/spec/unit/rhn_satellite/system_spec.rb +320 -0
- data/spec/unit/rhn_satellite/systemgroup_spec.rb +127 -0
- metadata +180 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe RhnSatellite::ChannelAccess do
|
5
|
+
before(:each) do
|
6
|
+
RhnSatellite::ChannelAccess.reset
|
7
|
+
conn = Object.new
|
8
|
+
conn.stubs(:call)
|
9
|
+
|
10
|
+
XMLRPC::Client.stubs(:new2).returns(conn)
|
11
|
+
|
12
|
+
RhnSatellite::ChannelAccess.username = 'user'
|
13
|
+
RhnSatellite::ChannelAccess.password = 'pwd'
|
14
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.login",'user','pwd').returns("token")
|
15
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.logout",'token')
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".disable_user_restrictions" do
|
19
|
+
it "disables the user restrictions" do
|
20
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with(
|
21
|
+
"channel.access.disableUserRestrictions",
|
22
|
+
"token",
|
23
|
+
'some_channel').returns(1)
|
24
|
+
|
25
|
+
RhnSatellite::ChannelAccess.disable_user_restrictions('some_channel').should eql(1)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".enable_user_restrictions" do
|
30
|
+
it "enables the user restrictions" do
|
31
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with(
|
32
|
+
"channel.access.enableUserRestrictions",
|
33
|
+
"token",
|
34
|
+
'some_channel').returns(1)
|
35
|
+
|
36
|
+
RhnSatellite::ChannelAccess.enable_user_restrictions('some_channel').should eql(1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".get_org_sharing" do
|
41
|
+
it "returns the org sharing access" do
|
42
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with(
|
43
|
+
"channel.access.getOrgSharing",
|
44
|
+
"token",
|
45
|
+
'some_channel').returns('public')
|
46
|
+
|
47
|
+
RhnSatellite::ChannelAccess.get_org_sharing('some_channel').should eql('public')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
describe ".set_org_sharing" do
|
51
|
+
it "sets the org sharing access" do
|
52
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with(
|
53
|
+
"channel.access.setOrgSharing",
|
54
|
+
"token",
|
55
|
+
'some_channel',
|
56
|
+
'public').returns(1)
|
57
|
+
|
58
|
+
RhnSatellite::ChannelAccess.set_org_sharing('some_channel','public').should eql(1)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe RhnSatellite::ChannelSoftware do
|
5
|
+
before(:each) do
|
6
|
+
RhnSatellite::ChannelSoftware.reset
|
7
|
+
conn = Object.new
|
8
|
+
conn.stubs(:call)
|
9
|
+
|
10
|
+
XMLRPC::Client.stubs(:new2).returns(conn)
|
11
|
+
|
12
|
+
RhnSatellite::ChannelSoftware.username = 'user'
|
13
|
+
RhnSatellite::ChannelSoftware.password = 'pwd'
|
14
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.login",'user','pwd').returns("token")
|
15
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.logout",'token')
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".clone" do
|
19
|
+
|
20
|
+
it "clones a channel" do
|
21
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with(
|
22
|
+
"channel.software.clone",
|
23
|
+
"token",
|
24
|
+
'old_channel',
|
25
|
+
{
|
26
|
+
'name' => 'new_channel',
|
27
|
+
'label' => 'some_label',
|
28
|
+
'summary' => 'summary'
|
29
|
+
},
|
30
|
+
true
|
31
|
+
).returns("123")
|
32
|
+
|
33
|
+
RhnSatellite::ChannelSoftware.clone('old_channel','new_channel','some_label','summary')
|
34
|
+
end
|
35
|
+
context "with additional options" do
|
36
|
+
it "should pass these options" do
|
37
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with(
|
38
|
+
"channel.software.clone",
|
39
|
+
"token",
|
40
|
+
'old_channel',
|
41
|
+
{
|
42
|
+
'name' => 'new_channel',
|
43
|
+
'label' => 'some_label',
|
44
|
+
'summary' => 'summary',
|
45
|
+
'parent_label' => 'blub'
|
46
|
+
},
|
47
|
+
true
|
48
|
+
).returns("123")
|
49
|
+
|
50
|
+
RhnSatellite::ChannelSoftware.clone('old_channel','new_channel','some_label','summary',true,'parent_label' => 'blub')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe ".list_children" do
|
56
|
+
it "lists all children of a software channel" do
|
57
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with(
|
58
|
+
"channel.software.listChildren",
|
59
|
+
"token",
|
60
|
+
'channel_label').returns("123")
|
61
|
+
|
62
|
+
RhnSatellite::ChannelSoftware.list_children('channel_label')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe RhnSatellite::Channel do
|
5
|
+
before(:each) { RhnSatellite::Channel.reset }
|
6
|
+
|
7
|
+
describe ".all" do
|
8
|
+
before(:each) do
|
9
|
+
conn = Object.new
|
10
|
+
conn.stubs(:call)
|
11
|
+
|
12
|
+
XMLRPC::Client.stubs(:new2).returns(conn)
|
13
|
+
|
14
|
+
RhnSatellite::Channel.username = 'user'
|
15
|
+
RhnSatellite::Channel.password = 'pwd'
|
16
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.login",'user','pwd').returns("token")
|
17
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.logout",'token')
|
18
|
+
end
|
19
|
+
it "logins and returns a bunch of channels" do
|
20
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("channel.listAllChannels","token").returns(["123","234"])
|
21
|
+
|
22
|
+
RhnSatellite::Channel.all.should eql(["123","234"])
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns an empty array on an empty answer" do
|
26
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("channel.listAllChannels","token").returns(nil)
|
27
|
+
|
28
|
+
RhnSatellite::Channel.all.should eql([])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "iterates the items over the block" do
|
32
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("channel.listAllChannels","token").returns(["123","234"])
|
33
|
+
RhnSatellite::Channel.all{|i| ["123","234"].include?(i).should be_true }.should eql(["123","234"])
|
34
|
+
end
|
35
|
+
describe ".get" do
|
36
|
+
context "with systems" do
|
37
|
+
before :each do
|
38
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('channel.listAllChannels',"token").returns([{'name' => "123"},{'name' => "234"}])
|
39
|
+
end
|
40
|
+
it "finds a system in all systems" do
|
41
|
+
RhnSatellite::Channel.get('123').should eql({'name' => '123'})
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns nil on an non-existant system" do
|
45
|
+
RhnSatellite::Channel.get('12333').should eql(nil)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context "without any systems" do
|
49
|
+
before :each do
|
50
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('channel.listAllChannels',"token").returns([])
|
51
|
+
end
|
52
|
+
it "returns nil" do
|
53
|
+
RhnSatellite::Channel.get('12333').should eql(nil)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
class TestDebug
|
5
|
+
include RhnSatellite::Common::Debug
|
6
|
+
end
|
7
|
+
|
8
|
+
describe RhnSatellite::Common::Debug do
|
9
|
+
it "should provide a way to set and query a debug flag" do
|
10
|
+
TestDebug.should respond_to(:debug_enabled)
|
11
|
+
TestDebug.should respond_to(:debug_enabled=)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should provide a way to set and query an output engine" do
|
15
|
+
TestDebug.should respond_to(:output)
|
16
|
+
TestDebug.should respond_to(:output=)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should provide a method to print debug messages on class and instance level" do
|
20
|
+
TestDebug.should respond_to(:debug)
|
21
|
+
TestDebug.new.should respond_to(:debug)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not have debugging enabled by default" do
|
25
|
+
TestDebug.debug_enabled.should == false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not print out a debug message if the debug flag is not set" do
|
29
|
+
output = Object.new
|
30
|
+
output.expects(:puts).with('foo').never
|
31
|
+
TestDebug.output = output
|
32
|
+
TestDebug.debug('foo')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should print out a debug message if the debug flag is set" do
|
36
|
+
TestDebug.debug_enabled = true
|
37
|
+
output = Object.new
|
38
|
+
output.expects(:puts).with('foo').once
|
39
|
+
TestDebug.output = output
|
40
|
+
TestDebug.debug('foo')
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
describe RhnSatellite::Common::Misc do
|
5
|
+
describe ".gen_date_time" do
|
6
|
+
it "uses now by default" do
|
7
|
+
now = Time.now
|
8
|
+
Time.expects(:now).once.returns(now)
|
9
|
+
(res=subject.gen_date_time).should be_kind_of(XMLRPC::DateTime)
|
10
|
+
res.min.should eql(now.min)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has the default as 'now'" do
|
14
|
+
now = Time.now
|
15
|
+
Time.expects(:now).once.returns(now)
|
16
|
+
(res=subject.gen_date_time('now')).should be_kind_of(XMLRPC::DateTime)
|
17
|
+
res.min.should eql(now.min)
|
18
|
+
end
|
19
|
+
|
20
|
+
[DateTime,Time].each do |type|
|
21
|
+
it "converts #{type.name} to a XMLRPC::DateTime" do
|
22
|
+
now = type.now
|
23
|
+
(res=subject.gen_date_time).should be_kind_of(XMLRPC::DateTime)
|
24
|
+
res.min.should eql(now.min)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "pass everything else" do
|
29
|
+
a = 'blub'
|
30
|
+
subject.gen_date_time(a).should eql(a)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
module RhnSatellite
|
5
|
+
class Test < RhnSatellite::Connection::Base
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module RhnSatellite
|
10
|
+
class Test2 < RhnSatellite::Connection::Base
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe RhnSatellite::Connection::Base do
|
15
|
+
describe "#reset" do
|
16
|
+
it "resets the used base" do
|
17
|
+
a = RhnSatellite::Test.send(:base)
|
18
|
+
RhnSatellite::Test.reset
|
19
|
+
a.should_not eql(RhnSatellite::Test.send(:base))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#base" do
|
24
|
+
it "differs based on the used class" do
|
25
|
+
RhnSatellite::Test.send(:base).should_not eql(RhnSatellite::Test2.send(:base))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
[:hostname,:username, :password].each do |field|
|
30
|
+
describe "##{field}" do
|
31
|
+
it "provides a way to set and read a #{field}" do
|
32
|
+
RhnSatellite::Test.should respond_to("#{field}=")
|
33
|
+
RhnSatellite::Test.should respond_to("#{field}")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "is used for the base connection" do
|
37
|
+
RhnSatellite::Test.reset
|
38
|
+
RhnSatellite::Test.send("#{field}=","foo")
|
39
|
+
RhnSatellite::Test.send(:base).instance_variable_get("@#{field}").should eql("foo")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
describe RhnSatellite::Connection::Handler do
|
5
|
+
|
6
|
+
[:hostname,:username, :password].each do |field|
|
7
|
+
it "provides a way to set and read a default #{field}" do
|
8
|
+
RhnSatellite::Connection::Handler.should respond_to("default_#{field}=")
|
9
|
+
RhnSatellite::Connection::Handler.should respond_to("default_#{field}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".instance_for" do
|
14
|
+
it "returns an instance of RhnSatellite::Connection::Handler" do
|
15
|
+
RhnSatellite::Connection::Handler.instance_for(:foo).should be_a(RhnSatellite::Connection::Handler)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "caches the instances" do
|
19
|
+
RhnSatellite::Connection::Handler.instance_for(:foo).should eql(RhnSatellite::Connection::Handler.instance_for(:foo))
|
20
|
+
end
|
21
|
+
|
22
|
+
it "takes default hostname if no argument is passed" do
|
23
|
+
RhnSatellite::Connection::Handler.default_hostname = 'blub'
|
24
|
+
RhnSatellite::Connection::Handler.instance_for(:default_hostname).instance_variable_get('@hostname').should eql('blub')
|
25
|
+
end
|
26
|
+
it "takes passed hostname" do
|
27
|
+
RhnSatellite::Connection::Handler.default_hostname = 'blub'
|
28
|
+
RhnSatellite::Connection::Handler.instance_for(:default_hostname2,'bla').instance_variable_get('@hostname').should eql('bla')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "takes default username if no argument is passed" do
|
32
|
+
RhnSatellite::Connection::Handler.default_username = 'user'
|
33
|
+
RhnSatellite::Connection::Handler.instance_for(:default_user,'bla').instance_variable_get('@username').should eql('user')
|
34
|
+
end
|
35
|
+
it "takes passed username" do
|
36
|
+
RhnSatellite::Connection::Handler.default_username = 'user'
|
37
|
+
RhnSatellite::Connection::Handler.instance_for(:default_user2,'bla','user2').instance_variable_get('@username').should eql('user2')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "takes default password if no argument is passed" do
|
41
|
+
RhnSatellite::Connection::Handler.default_password = 'secret'
|
42
|
+
RhnSatellite::Connection::Handler.instance_for(:default_pwd,'bla','user').instance_variable_get('@password').should eql('secret')
|
43
|
+
end
|
44
|
+
it "takes passed password" do
|
45
|
+
RhnSatellite::Connection::Handler.default_password = 'secret'
|
46
|
+
RhnSatellite::Connection::Handler.instance_for(:default_pwd2,'bla','user2','secret2').instance_variable_get('@password').should eql('secret2')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "takes default timeout if no argument is passed" do
|
50
|
+
RhnSatellite::Connection::Handler.default_timeout = 60
|
51
|
+
RhnSatellite::Connection::Handler.instance_for(:default_timeout,'bla','user','foo',60).instance_variable_get('@timeout').should eql(60)
|
52
|
+
end
|
53
|
+
it "takes passed timeout" do
|
54
|
+
RhnSatellite::Connection::Handler.default_timeout = 60
|
55
|
+
RhnSatellite::Connection::Handler.instance_for(:default_timeout2,'bla','user2','secret2',65).instance_variable_get('@timeout').should eql(65)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "defaults https to true" do
|
59
|
+
RhnSatellite::Connection::Handler.instance_for(:default_https,'bla','user','secret2').instance_variable_get('@https').should eql(true)
|
60
|
+
end
|
61
|
+
it "takes passed https setting" do
|
62
|
+
RhnSatellite::Connection::Handler.instance_for(:default_https2,'bla','user2','secret2',30,false).instance_variable_get('@https').should eql(false)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe ".reset" do
|
67
|
+
it "removes a cached instance" do
|
68
|
+
a = RhnSatellite::Connection::Handler.instance_for(:cache_reset)
|
69
|
+
RhnSatellite::Connection::Handler.reset_instance(:cache_reset)
|
70
|
+
RhnSatellite::Connection::Handler.instance_for(:cache_reset).should_not eql(a)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "does not raise an error on an inexistant instance" do
|
74
|
+
lambda { RhnSatellite::Connection::Handler.reset_instance(:blablablabla) }.should_not raise_error
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe ".reset_all" do
|
79
|
+
it "resets all connections" do
|
80
|
+
a = RhnSatellite::Connection::Handler.instance_for(:cache_reset)
|
81
|
+
RhnSatellite::Connection::Handler.send(:instances).should_not be_empty
|
82
|
+
RhnSatellite::Connection::Handler.reset_all
|
83
|
+
RhnSatellite::Connection::Handler.send(:instances).should be_empty
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#connect" do
|
88
|
+
before :each do
|
89
|
+
RhnSatellite::Connection::Handler.default_hostname = 'connecttest'
|
90
|
+
end
|
91
|
+
|
92
|
+
it "creates a new connection with the passed timeout" do
|
93
|
+
RhnSatellite::Connection::Handler.default_timeout = 60
|
94
|
+
XMLRPC::Client.expects(:new2).with('https://connecttest/rpc/api',nil,60)
|
95
|
+
a = RhnSatellite::Connection::Handler.instance_for(:connect)
|
96
|
+
a.connect
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#disconnect" do
|
101
|
+
it "disconnects" do
|
102
|
+
a = RhnSatellite::Connection::Handler.instance_for(:disconnect)
|
103
|
+
a.connect
|
104
|
+
a.connected?.should eql(true)
|
105
|
+
a.disconnect
|
106
|
+
a.connected?.should eql(false)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#make_call" do
|
111
|
+
context "without a connection"
|
112
|
+
it "raises an exception" do
|
113
|
+
a = RhnSatellite::Connection::Handler.instance_for(:make_call1)
|
114
|
+
a.connected?.should be(false)
|
115
|
+
lambda { a.make_call(1,2) }.should raise_error
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with a connection" do
|
120
|
+
it "calls out to xmlrpc" do
|
121
|
+
xmlrpc = Object.new
|
122
|
+
XMLRPC::Client.expects(:new2).returns(xmlrpc)
|
123
|
+
xmlrpc.expects(:call).with(1,2).returns "foo"
|
124
|
+
a = RhnSatellite::Connection::Handler.instance_for(:make_call2)
|
125
|
+
a.connect
|
126
|
+
a.make_call(1,2).should eql('foo')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#login" do
|
131
|
+
it "connects with username and password" do
|
132
|
+
a = RhnSatellite::Connection::Handler.instance_for(:login,'blub','user1','password')
|
133
|
+
xmlrpc = Object.new
|
134
|
+
XMLRPC::Client.expects(:new2).returns(xmlrpc)
|
135
|
+
xmlrpc.expects(:call).with('auth.login','user1','password').returns "some_token"
|
136
|
+
a.connect
|
137
|
+
a.login
|
138
|
+
end
|
139
|
+
|
140
|
+
it "connects with a duration" do
|
141
|
+
a = RhnSatellite::Connection::Handler.instance_for(:login2,'blub','user1','password')
|
142
|
+
xmlrpc = Object.new
|
143
|
+
XMLRPC::Client.expects(:new2).returns(xmlrpc)
|
144
|
+
xmlrpc.expects(:call).with('auth.login','user1','password',10).returns "some_token2"
|
145
|
+
a.connect
|
146
|
+
a.login(10)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "does not call login again if we are logged in" do
|
150
|
+
a = RhnSatellite::Connection::Handler.instance_for(:login3,'blub','user1','password')
|
151
|
+
xmlrpc = Object.new
|
152
|
+
XMLRPC::Client.expects(:new2).returns(xmlrpc)
|
153
|
+
xmlrpc.expects(:call).with('auth.login','user1','password').returns "some_token3"
|
154
|
+
a.connect
|
155
|
+
a.login.should(eql("some_token3"))
|
156
|
+
a.login.should(eql("some_token3"))
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#logout" do
|
161
|
+
it "calls logout and clears the auth_token" do
|
162
|
+
a = RhnSatellite::Connection::Handler.instance_for(:logout,'blub','user1','password')
|
163
|
+
xmlrpc = Object.new
|
164
|
+
XMLRPC::Client.expects(:new2).returns(xmlrpc)
|
165
|
+
xmlrpc.expects(:call).with('auth.login','user1','password').returns "some_token4"
|
166
|
+
xmlrpc.expects(:call).with('auth.logout','some_token4')
|
167
|
+
a.connect
|
168
|
+
a.login.should(eql("some_token4"))
|
169
|
+
a.logout.should(eql(true))
|
170
|
+
a.instance_variable_get("@auth_token").should be_nil
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should not logout if we're not logged in" do
|
174
|
+
a = RhnSatellite::Connection::Handler.instance_for(:logout,'blub','user1','password')
|
175
|
+
xmlrpc = Object.new
|
176
|
+
XMLRPC::Client.expects(:new2).returns(xmlrpc)
|
177
|
+
xmlrpc.expects(:call).with('auth.logout','some_token4').never
|
178
|
+
a.connect
|
179
|
+
a.logout.should(eql(true))
|
180
|
+
a.instance_variable_get("@auth_token").should be_nil
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "#in_transaction" do
|
185
|
+
context "with login" do
|
186
|
+
it "logs in and out" do
|
187
|
+
a = RhnSatellite::Connection::Handler.instance_for(:logout,'blub','user1','password')
|
188
|
+
xmlrpc = Object.new
|
189
|
+
XMLRPC::Client.expects(:new2).returns(xmlrpc)
|
190
|
+
a.expects(:login).once
|
191
|
+
a.expects(:logout).once
|
192
|
+
|
193
|
+
a.in_transaction(true){ "block" }.should eql("block")
|
194
|
+
end
|
195
|
+
it "passes the token to the block" do
|
196
|
+
a = RhnSatellite::Connection::Handler.instance_for(:logout,'blub','user1','password')
|
197
|
+
xmlrpc = Object.new
|
198
|
+
XMLRPC::Client.expects(:new2).returns(xmlrpc)
|
199
|
+
xmlrpc.expects(:call).with('auth.login','user1','password').returns "some_token5"
|
200
|
+
a.expects(:logout).once
|
201
|
+
|
202
|
+
a.in_transaction(true){|token| token.should eql("some_token5"); "block" }.should eql("block")
|
203
|
+
end
|
204
|
+
end
|
205
|
+
context "without login" do
|
206
|
+
it "does not log in and out" do
|
207
|
+
a = RhnSatellite::Connection::Handler.instance_for(:logout,'blub','user1','password')
|
208
|
+
xmlrpc = Object.new
|
209
|
+
XMLRPC::Client.expects(:new2).returns(xmlrpc)
|
210
|
+
a.expects(:login).never
|
211
|
+
a.expects(:logout).never
|
212
|
+
|
213
|
+
a.in_transaction{ "block" }.should eql("block")
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
describe "#default_call" do
|
218
|
+
it "delegates everything to a logged in transaction" do
|
219
|
+
a = RhnSatellite::Connection::Handler.instance_for(:logout,'blub','user1','password')
|
220
|
+
a.stubs(:make_call).with('auth.login','user1','password').returns "some_token5"
|
221
|
+
a.expects(:logout).twice
|
222
|
+
a.expects(:make_call).with('some_method','some_token5','arg1','arg2').returns("result")
|
223
|
+
a.expects(:make_call).with('some_method2','some_token5').returns("result2")
|
224
|
+
|
225
|
+
a.default_call('some_method','arg1','arg2').should eql('result')
|
226
|
+
a.default_call('some_method2').should eql('result2')
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|