solusvm 1.4.0 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/LICENSE +1 -1
  4. data/README.markdown +159 -116
  5. data/Rakefile +3 -33
  6. data/bin/solusvm +3 -4
  7. data/lib/solusvm.rb +1 -3
  8. data/lib/solusvm/base.rb +101 -46
  9. data/lib/solusvm/cli.rb +8 -8
  10. data/lib/solusvm/cli/base_cli.rb +3 -3
  11. data/lib/solusvm/cli/client_cli.rb +3 -5
  12. data/lib/solusvm/cli/general_cli.rb +3 -5
  13. data/lib/solusvm/cli/node_cli.rb +3 -5
  14. data/lib/solusvm/cli/reseller_cli.rb +3 -5
  15. data/lib/solusvm/cli/server_cli.rb +4 -6
  16. data/lib/solusvm/client.rb +45 -27
  17. data/lib/solusvm/errors.rb +3 -0
  18. data/lib/solusvm/general.rb +11 -12
  19. data/lib/solusvm/hash.rb +1 -11
  20. data/lib/solusvm/node.rb +33 -21
  21. data/lib/solusvm/reseller.rb +53 -49
  22. data/lib/solusvm/server.rb +188 -52
  23. data/lib/solusvm/version.rb +2 -2
  24. data/test/cli/test_base_cli.rb +14 -4
  25. data/test/cli/test_client_cli.rb +13 -13
  26. data/test/cli/test_general_cli.rb +7 -7
  27. data/test/cli/test_node_cli.rb +13 -13
  28. data/test/cli/test_reseller_cli.rb +11 -11
  29. data/test/cli/test_server_cli.rb +61 -61
  30. data/test/sham_rack_stubs/base/parse-response.json +4 -0
  31. data/test/sham_rack_stubs/client/authenticate.json +4 -0
  32. data/test/sham_rack_stubs/client/change-password.json +6 -0
  33. data/test/sham_rack_stubs/client/create.json +9 -0
  34. data/test/sham_rack_stubs/client/delete.json +4 -0
  35. data/test/sham_rack_stubs/client/exists.json +4 -0
  36. data/test/sham_rack_stubs/client/list-empty.json +5 -0
  37. data/test/sham_rack_stubs/client/list.json +30 -0
  38. data/test/sham_rack_stubs/general/isos-empty.json +5 -0
  39. data/test/sham_rack_stubs/general/isos.json +5 -0
  40. data/test/sham_rack_stubs/general/plans-empty.json +5 -0
  41. data/test/sham_rack_stubs/general/plans.json +5 -0
  42. data/test/sham_rack_stubs/general/templates-empty.json +7 -0
  43. data/test/sham_rack_stubs/general/templates.json +7 -0
  44. data/test/sham_rack_stubs/generic/error.json +4 -0
  45. data/test/sham_rack_stubs/node/available-ips-empty.json +6 -0
  46. data/test/sham_rack_stubs/node/available-ips.json +6 -0
  47. data/test/sham_rack_stubs/node/ids.json +5 -0
  48. data/test/sham_rack_stubs/node/list-empty.json +5 -0
  49. data/test/sham_rack_stubs/node/list-groups.json +5 -0
  50. data/test/sham_rack_stubs/node/list.json +5 -0
  51. data/test/sham_rack_stubs/node/statistics.json +21 -0
  52. data/test/sham_rack_stubs/node/virtualservers-empty.json +5 -0
  53. data/test/sham_rack_stubs/node/virtualservers.json +19 -0
  54. data/test/sham_rack_stubs/node/xenresources.json +6 -0
  55. data/test/sham_rack_stubs/reseller/change-resources.json +18 -0
  56. data/test/sham_rack_stubs/reseller/create.json +25 -0
  57. data/test/sham_rack_stubs/reseller/delete.json +4 -0
  58. data/test/sham_rack_stubs/reseller/info.json +24 -0
  59. data/test/sham_rack_stubs/reseller/list-empty.json +5 -0
  60. data/test/sham_rack_stubs/reseller/list.json +5 -0
  61. data/test/sham_rack_stubs/server/add-ip.json +5 -0
  62. data/test/sham_rack_stubs/server/boot.json +4 -0
  63. data/test/sham_rack_stubs/server/change-bootorder.json +4 -0
  64. data/test/sham_rack_stubs/server/change-hostname.json +5 -0
  65. data/test/sham_rack_stubs/server/change-owner.json +4 -0
  66. data/test/sham_rack_stubs/server/change-plan.json +4 -0
  67. data/test/sham_rack_stubs/server/change-rootpassword.json +5 -0
  68. data/test/sham_rack_stubs/server/change-vncpass.json +5 -0
  69. data/test/sham_rack_stubs/server/console.json +13 -0
  70. data/test/sham_rack_stubs/server/create.json +13 -0
  71. data/test/sham_rack_stubs/server/del-ip.json +4 -0
  72. data/test/sham_rack_stubs/server/exists.json +4 -0
  73. data/test/sham_rack_stubs/server/info-all.json +16 -0
  74. data/test/sham_rack_stubs/server/info.json +15 -0
  75. data/test/sham_rack_stubs/server/mountiso.json +4 -0
  76. data/test/sham_rack_stubs/server/network-disable.json +4 -0
  77. data/test/sham_rack_stubs/server/network-enable.json +4 -0
  78. data/test/sham_rack_stubs/server/pae-disable.json +4 -0
  79. data/test/sham_rack_stubs/server/pae-enable.json +4 -0
  80. data/test/sham_rack_stubs/server/reboot.json +4 -0
  81. data/test/sham_rack_stubs/server/rebuild.json +4 -0
  82. data/test/sham_rack_stubs/server/resume.json +4 -0
  83. data/test/sham_rack_stubs/server/shutdown.json +4 -0
  84. data/test/sham_rack_stubs/server/status.json +4 -0
  85. data/test/sham_rack_stubs/server/suspend.json +4 -0
  86. data/test/sham_rack_stubs/server/terminate.json +4 -0
  87. data/test/sham_rack_stubs/server/tun-disable.json +4 -0
  88. data/test/sham_rack_stubs/server/tun-enable.json +4 -0
  89. data/test/sham_rack_stubs/server/unmountiso.json +4 -0
  90. data/test/sham_rack_stubs/server/vnc.json +8 -0
  91. data/test/solusvm/test_base.rb +34 -56
  92. data/test/solusvm/test_cli.rb +3 -3
  93. data/test/solusvm/test_client.rb +56 -66
  94. data/test/solusvm/test_general.rb +34 -19
  95. data/test/solusvm/test_hash.rb +0 -9
  96. data/test/solusvm/test_node.rb +66 -72
  97. data/test/solusvm/test_reseller.rb +47 -58
  98. data/test/solusvm/test_server.rb +149 -164
  99. data/test/test_helper.rb +43 -31
  100. metadata +173 -189
  101. data/.document +0 -5
  102. data/.gitignore +0 -25
  103. data/.travis.yml +0 -12
  104. data/solusvm.gemspec +0 -33
  105. data/test/vcr_cassettes/base/invalid_key.yml +0 -19
  106. data/test/vcr_cassettes/base/invalid_status.yml +0 -19
  107. data/test/vcr_cassettes/base/nonexistent_node.yml +0 -19
  108. data/test/vcr_cassettes/base/parse_response.yml +0 -28
  109. data/test/vcr_cassettes/base/statusmsg.yml +0 -28
  110. data/test/vcr_cassettes/base/successful.yml +0 -68
  111. data/test/vcr_cassettes/base/successful_instance_config.yml +0 -28
  112. data/test/vcr_cassettes/base/unauthorized_ip.yml +0 -19
  113. data/test/vcr_cassettes/client/authenticate.yml +0 -37
  114. data/test/vcr_cassettes/client/change_password.yml +0 -39
  115. data/test/vcr_cassettes/client/create.yml +0 -42
  116. data/test/vcr_cassettes/client/delete.yml +0 -37
  117. data/test/vcr_cassettes/client/exists.yml +0 -20
  118. data/test/vcr_cassettes/client/list.yml +0 -66
  119. data/test/vcr_cassettes/general/isos.yml +0 -38
  120. data/test/vcr_cassettes/general/plans.yml +0 -38
  121. data/test/vcr_cassettes/general/templates.yml +0 -38
  122. data/test/vcr_cassettes/node/available_ips.yml +0 -41
  123. data/test/vcr_cassettes/node/ids.yml +0 -21
  124. data/test/vcr_cassettes/node/list.yml +0 -38
  125. data/test/vcr_cassettes/node/list_groups.yml +0 -20
  126. data/test/vcr_cassettes/node/statistics.yml +0 -32
  127. data/test/vcr_cassettes/node/virtualservers.yml +0 -67
  128. data/test/vcr_cassettes/node/xenresources.yml +0 -22
  129. data/test/vcr_cassettes/reseller/change_resources.yml +0 -27
  130. data/test/vcr_cassettes/reseller/create.yml +0 -27
  131. data/test/vcr_cassettes/reseller/delete.yml +0 -15
  132. data/test/vcr_cassettes/reseller/info.yml +0 -27
  133. data/test/vcr_cassettes/reseller/list.yml +0 -27
  134. data/test/vcr_cassettes/server/.yml +0 -1017
  135. data/test/vcr_cassettes/server/add_ip.yml +0 -15
  136. data/test/vcr_cassettes/server/boot.yml +0 -15
  137. data/test/vcr_cassettes/server/change_bootorder.yml +0 -15
  138. data/test/vcr_cassettes/server/change_consolepass.yml +0 -16
  139. data/test/vcr_cassettes/server/change_hostname.yml +0 -15
  140. data/test/vcr_cassettes/server/change_owner.yml +0 -15
  141. data/test/vcr_cassettes/server/change_plan.yml +0 -15
  142. data/test/vcr_cassettes/server/change_rootpassword.yml +0 -15
  143. data/test/vcr_cassettes/server/change_vncpass.yml +0 -15
  144. data/test/vcr_cassettes/server/console.yml +0 -28
  145. data/test/vcr_cassettes/server/create.yml +0 -27
  146. data/test/vcr_cassettes/server/del_ip.yml +0 -15
  147. data/test/vcr_cassettes/server/exists.yml +0 -15
  148. data/test/vcr_cassettes/server/info.yml +0 -27
  149. data/test/vcr_cassettes/server/info_all.yml +0 -15
  150. data/test/vcr_cassettes/server/mountiso.yml +0 -15
  151. data/test/vcr_cassettes/server/network_disable.yml +0 -15
  152. data/test/vcr_cassettes/server/network_enable.yml +0 -15
  153. data/test/vcr_cassettes/server/pae_disable.yml +0 -15
  154. data/test/vcr_cassettes/server/pae_enable.yml +0 -15
  155. data/test/vcr_cassettes/server/reboot.yml +0 -15
  156. data/test/vcr_cassettes/server/rebuild.yml +0 -15
  157. data/test/vcr_cassettes/server/resume.yml +0 -15
  158. data/test/vcr_cassettes/server/shutdown.yml +0 -15
  159. data/test/vcr_cassettes/server/status.yml +0 -15
  160. data/test/vcr_cassettes/server/suspend.yml +0 -15
  161. data/test/vcr_cassettes/server/terminate.yml +0 -27
  162. data/test/vcr_cassettes/server/tun_disable.yml +0 -15
  163. data/test/vcr_cassettes/server/tun_enable.yml +0 -15
  164. data/test/vcr_cassettes/server/unmountiso.yml +0 -15
  165. data/test/vcr_cassettes/server/vnc.yml +0 -15
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "ISO mounted"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Virtual server network disabled"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Virtual server network enabled"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Disabled"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Enabled"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Virtual server rebooted"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Virtual server is being rebuilt"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Virtual server unsuspended"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Virtual server shutdown"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "online"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Virtual server suspended"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Virtual server terminated"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Disabled"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "Enabled"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "ISO unmounted"
4
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "status": "success",
3
+ "statusmsg": "",
4
+ "type": "kvm|hvm",
5
+ "vncip": "ip of hos",
6
+ "vncport": "vncport",
7
+ "vncpassword": "vnc password"
8
+ }
@@ -1,53 +1,37 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TestBase < Test::Unit::TestCase
4
-
5
4
  def setup
6
- @base = Solusvm::Base.new(solusvm_params)
5
+ @base = SolusVM::Base.new(solusvm_params)
7
6
  end
8
7
 
9
8
  def test_valid_server_types
10
- assert_equal 3, Solusvm::Base::VALID_SERVER_TYPES.size
11
- assert_equal ['openvz', 'xen', 'xen hvm'].sort, Solusvm::Base::VALID_SERVER_TYPES.sort
9
+ assert_equal 3, SolusVM::Base::VALID_SERVER_TYPES.size
10
+ assert_equal ['openvz', 'xen', 'xen hvm'].sort, SolusVM::Base::VALID_SERVER_TYPES.sort
12
11
  end
13
12
 
14
13
  def test_parse_response
15
14
  assert_nil @base.returned_parameters
16
- VCR.use_cassette "base/parse_response" do
17
- @base.perform_request(action: 'test', vserverid: 1)
18
- end
19
- params = @base.returned_parameters
20
-
21
- assert_equal 10, params.size
22
- assert_equal '123.123.123.123', params['mainipaddress']
23
- assert_equal 'console-123', params['consoleuser']
24
- assert_equal '100', params['vserverid']
25
- assert_equal 'Virtual server created', params['statusmsg']
26
- assert_equal 'vm101|101', params['virtid']
27
- assert_equal '123456', params['consolepassword']
28
- assert_equal '122.122.122.122,111.111.111.111', params['extraipaddress']
29
- assert_equal 'server.hostname.com', params['hostname']
30
- assert_equal '123456', params['rootpassword']
31
- assert_equal 'success', params['status']
15
+
16
+ stub_response 'base/parse-response'
17
+
18
+ assert @base.perform_request(action: 'test', vserverid: 1)
19
+
20
+ res = @base.returned_parameters
21
+ assert res.is_a? Hash
22
+ assert_not_empty res
32
23
  end
33
24
 
34
25
  def test_successful
35
- VCR.use_cassette "base/successful" do
36
- @base.perform_request(action: 'testsuccess', vserverid: 1)
37
- assert @base.successful?
26
+ stub_response 'base/parse-response'
38
27
 
39
- @base.perform_request(action: 'testfail', vserverid: 1)
40
- assert_equal "error message", @base.statusmsg
28
+ @base.perform_request(action: 'testsuccess', vserverid: 1)
29
+ assert @base.successful?
41
30
 
42
- @base.perform_request(action: 'testnostatus', vserverid: 1)
43
- assert @base.successful?
44
- end
31
+ stub_response 'generic/error'
45
32
 
46
- VCR.use_cassette "base/successful_instance_config" do
47
- @base = Solusvm::Base.new(api_key: "instance_key", api_id: "instance_id", url: "http://www.test.com/api" )
48
- @base.perform_request(action: 'testconfig', vserverid: 1)
49
- assert @base.successful?
50
- end
33
+ @base.perform_request(action: 'testsuccess', vserverid: 1)
34
+ assert !@base.successful?
51
35
  end
52
36
 
53
37
  def test_api_login
@@ -55,14 +39,14 @@ class TestBase < Test::Unit::TestCase
55
39
  end
56
40
 
57
41
  def test_statusmsg
58
- VCR.use_cassette "base/statusmsg" do
59
- @base.perform_request(action: 'testsuccess', vserverid: 1)
60
- end
61
- assert_equal 'Virtual server created', @base.statusmsg
42
+ stub_response 'base/parse-response'
43
+
44
+ assert @base.perform_request(action: 'testsuccess')
45
+ assert_equal 'The status message', @base.statusmsg
62
46
  end
63
47
 
64
48
  def test_validate_server_type
65
- Solusvm::Base::VALID_SERVER_TYPES.each do |type|
49
+ SolusVM::Base::VALID_SERVER_TYPES.each do |type|
66
50
  assert @base.validate_server_type(type) { true }
67
51
  end
68
52
 
@@ -72,38 +56,32 @@ class TestBase < Test::Unit::TestCase
72
56
  end
73
57
 
74
58
  def test_unautorized_ip
75
- VCR.use_cassette "base/unauthorized_ip" do
76
- @base.perform_request(action: 'unauthorized')
59
+ setup_sham_rack { "Invalid ipaddress" }
77
60
 
78
- assert !@base.successful?
79
- assert_equal "This IP is not authorized to use the API", @base.statusmsg
61
+ assert_raise SolusVM::AuthenticationError do
62
+ assert !@base.perform_request(action: 'unauthorized')
80
63
  end
81
64
  end
82
65
 
83
66
  def test_invalid_key_or_id
84
- VCR.use_cassette "base/invalid_key" do
85
- @base.perform_request(action: 'badkey')
67
+ setup_sham_rack { "Invalid id or key" }
86
68
 
87
- assert !@base.successful?
88
- assert_equal "Invalid ID or key", @base.statusmsg
69
+ assert_raise SolusVM::AuthenticationError do
70
+ assert !@base.perform_request(action: 'badkey')
89
71
  end
90
72
  end
91
73
 
92
74
  def test_node_does_not_exist
93
- VCR.use_cassette "base/nonexistent_node" do
94
- @base.perform_request(action: 'nodeexist')
75
+ setup_sham_rack { "Node not found" }
95
76
 
96
- assert !@base.successful?
97
- assert_equal "Node does not exist", @base.statusmsg
98
- end
77
+ assert !@base.perform_request(action: 'nodeexist')
78
+ assert_equal "Node does not exist", @base.statusmsg
99
79
  end
100
80
 
101
81
  def test_invalid_http_status
102
- VCR.use_cassette "base/invalid_status" do
103
- @base.perform_request(action: 'httperror')
82
+ setup_sham_rack { status 404 }
104
83
 
105
- assert !@base.successful?
106
- assert_equal "Bad HTTP Status: 404", @base.statusmsg
107
- end
84
+ assert !@base.perform_request(action: 'httperror')
85
+ assert_equal "Bad HTTP Status: 404", @base.statusmsg
108
86
  end
109
87
  end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
  require 'solusvm/cli'
3
3
 
4
- class TestCli < Test::Unit::TestCase
4
+ class TestCLI < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
7
  # Prevents mocha from stubbing non existent methods so that we now if the CLI is failing because
@@ -10,8 +10,8 @@ class TestCli < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  def test_should_print_version
13
- $stdout.expects(:puts).with(Solusvm::VERSION)
14
- Solusvm::Cli.start %W(version)
13
+ $stdout.expects(:puts).with(SolusVM::VERSION)
14
+ SolusVM::CLI.start %W(version)
15
15
  end
16
16
 
17
17
  end
@@ -1,108 +1,98 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TestClient < Test::Unit::TestCase
4
-
5
4
  def setup
6
- @client = Solusvm::Client.new(solusvm_params)
5
+ @client = SolusVM::Client.new(solusvm_params)
7
6
  end
8
7
 
9
8
  def test_create
10
- options = {username: 'vps123', password: '123456', email: 'email@address.com', firstname: 'phill', lastname: 'smith'}
11
- VCR.use_cassette "client/create" do
12
- @client.create(options)
13
- end
14
- params = @client.returned_parameters
15
- assert_equal options[:username], params['username']
16
- assert_equal options[:firstname], params['firstname']
17
- assert_equal options[:lastname], params['lastname']
18
- assert_equal options[:password], params['password']
19
- assert_equal options[:email], params['email']
20
- assert_equal 'Successfully added client', params['statusmsg']
21
- assert_equal 'success', params['status']
9
+ stub_response 'client/create'
10
+
11
+ options = {
12
+ username: 'vps123',
13
+ password: '123456',
14
+ email: 'email@address.com',
15
+ firstname: 'phill',
16
+ lastname: 'smith'
17
+ }
18
+
19
+ assert @client.create(options).is_a? Hash
20
+ assert @client.successful?
22
21
  end
23
22
 
24
23
  def test_create_fail
25
- VCR.use_cassette "client/create" do
26
- assert ! @client.create
27
- end
28
- assert_equal 'Empty username field', @client.statusmsg
24
+ stub_response 'generic/error'
25
+
26
+ assert !@client.create
29
27
  end
30
28
 
31
29
  def test_exists
32
- VCR.use_cassette "client/exists" do
33
- assert @client.exists?("vps123")
34
- end
35
- assert_equal 'Client exists', @client.statusmsg
30
+ stub_response 'client/exists'
31
+
32
+ assert @client.exists?("vps123")
33
+ assert @client.successful?
36
34
  end
37
35
 
38
36
  def test_change_password
39
- VCR.use_cassette "client/change_password" do
40
- assert @client.change_password("vps123","123456")
41
- end
37
+ stub_response 'client/change-password'
38
+
39
+ assert @client.change_password("vps123","123456")
40
+ assert @client.successful?
42
41
  end
43
42
 
44
43
  def test_change_password_fail
45
- VCR.use_cassette "client/change_password" do
46
- assert ! @client.change_password("vps13","thecake")
47
- end
44
+ stub_response 'generic/error'
45
+
46
+ assert !@client.change_password("vps13","thecake")
48
47
  end
49
48
 
50
49
  def test_authenticate
51
- VCR.use_cassette "client/authenticate" do
52
- assert @client.authenticate('u', 'p')
53
- end
50
+ stub_response 'client/authenticate'
51
+
52
+ assert @client.authenticate('u', 'p')
53
+ assert @client.successful?
54
54
  end
55
55
 
56
56
  def test_authenticate_fail
57
- VCR.use_cassette "client/authenticate" do
58
- assert ! @client.authenticate('u', 'notp')
59
- end
60
- assert_equal 'invalid username or password', @client.statusmsg
57
+ stub_response 'generic/error'
58
+
59
+ assert !@client.authenticate('u', 'notp')
61
60
  end
62
61
 
63
62
  def test_delete
64
- VCR.use_cassette "client/delete" do
65
- assert @client.delete("vps123")
66
- end
63
+ stub_response 'client/delete'
64
+
65
+ assert @client.delete("vps123")
66
+ assert @client.successful?
67
67
  end
68
68
 
69
69
  def test_delete_fail
70
- VCR.use_cassette "client/delete" do
71
- assert !@client.delete("novps")
72
- end
70
+ stub_response 'generic/error'
71
+
72
+ assert !@client.delete("novps")
73
73
  end
74
74
 
75
75
  def test_list
76
- @client = Solusvm::Client.new(api_id: "api_id1", api_key: api_login[:key], url: 'http://www.example.com/api')
77
- VCR.use_cassette "client/list" do
78
- @client.list
79
- end
80
-
81
- client = @client.returned_parameters["clients"]["client"].first
82
-
83
- assert_equal "1", client["id"]
84
- assert_equal "vps123", client["username"]
85
- assert_equal "vps123@email.com", client["email"]
86
- assert_equal "phill", client["firstname"]
87
- assert_equal "smith", client["lastname"]
88
- assert_equal "VPS Co", client["company"]
89
- assert_equal "Client", client["level"]
90
- assert_equal "Active", client["status"]
91
- assert_equal "2009-01-01", client["created"]
92
- assert_equal "2010-04-23", client["lastlogin"]
76
+ stub_response 'client/list'
77
+
78
+ list = @client.list
79
+
80
+ assert list.is_a? Array
81
+ assert_not_empty list
93
82
  end
94
83
 
95
84
  def test_list_empty
96
- @client = Solusvm::Client.new(api_id: "api_id2", api_key: api_login[:key], url: 'http://www.example.com/api')
97
- VCR.use_cassette "client/list" do
98
- assert @client.list.empty?
99
- end
85
+ stub_response 'client/list-empty'
86
+
87
+ list = @client.list
88
+
89
+ assert list.is_a? Array
90
+ assert_empty @client.list
100
91
  end
101
92
 
102
93
  def test_list_fail
103
- @client = Solusvm::Client.new(api_id: "api_id3", api_key: api_login[:key], url: 'http://www.example.com/api')
104
- VCR.use_cassette "client/list" do
105
- assert_nil @client.list
106
- end
94
+ stub_response 'generic/error'
95
+
96
+ assert_nil @client.list
107
97
  end
108
98
  end
@@ -2,20 +2,25 @@ require 'test_helper'
2
2
 
3
3
  class TestGeneral < Test::Unit::TestCase
4
4
  def setup
5
- @general = Solusvm::General.new(solusvm_params)
5
+ @general = SolusVM::General.new(solusvm_params)
6
6
  end
7
7
 
8
8
  def test_templates
9
- VCR.use_cassette "general/templates" do
10
- assert_equal %w(template1 template2 template3), @general.templates('xen')
11
- end
9
+ stub_response 'general/templates'
10
+
11
+ list = @general.templates('xen')
12
+
13
+ assert list.is_a? Array
14
+ assert_not_empty list
15
+ assert @general.successful?
12
16
  end
13
17
 
14
18
  # TODO: Refactor so that the lib is not validating server types
15
19
  def test_templates_empty
16
- VCR.use_cassette "general/templates" do
17
- assert !@general.templates('openvz')
18
- end
20
+ stub_response 'general/templates-empty'
21
+
22
+ assert !@general.templates('xen')
23
+ assert @general.successful?
19
24
  end
20
25
 
21
26
  def test_templates_with_invalid_type
@@ -23,15 +28,20 @@ class TestGeneral < Test::Unit::TestCase
23
28
  end
24
29
 
25
30
  def test_plans
26
- VCR.use_cassette "general/plans" do
27
- assert_equal %w(plan1 plan2 plan3 plan4), @general.plans('xen')
28
- end
31
+ stub_response 'general/plans'
32
+
33
+ list = @general.plans('xen')
34
+
35
+ assert list.is_a? Array
36
+ assert_not_empty list
37
+ assert @general.successful?
29
38
  end
30
39
 
31
40
  def test_plans_empty
32
- VCR.use_cassette "general/plans" do
33
- assert !@general.plans('openvz')
34
- end
41
+ stub_response 'general/plans-empty'
42
+
43
+ assert !@general.plans('xen')
44
+ assert @general.successful?
35
45
  end
36
46
 
37
47
  def test_plans_with_invalid_type
@@ -39,15 +49,20 @@ class TestGeneral < Test::Unit::TestCase
39
49
  end
40
50
 
41
51
  def test_isos
42
- VCR.use_cassette "general/isos" do
43
- assert_equal %w(iso1 iso2 iso3), @general.isos('xen')
44
- end
52
+ stub_response 'general/isos'
53
+
54
+ list = @general.isos('xen')
55
+
56
+ assert list.is_a? Array
57
+ assert_not_empty list
58
+ assert @general.successful?
45
59
  end
46
60
 
47
61
  def test_isos_empty
48
- VCR.use_cassette "general/isos" do
49
- assert !@general.isos('openvz')
50
- end
62
+ stub_response 'general/isos-empty'
63
+
64
+ assert !@general.isos('xen')
65
+ assert @general.successful?
51
66
  end
52
67
 
53
68
  def test_isos_with_invalid_type