panelbeater 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ spec = Gem::Specification.new do |s|
17
17
 
18
18
  # Change these as appropriate
19
19
  s.name = "panelbeater"
20
- s.version = "0.1.3"
20
+ s.version = "0.1.4"
21
21
  s.summary = "A gem for communicating with the cPanel and WHM API's"
22
22
  s.author = "Jamie Dyer"
23
23
  s.email = "jamie@kernowsoul.com"
@@ -1,4 +1,4 @@
1
- module CpanelApi
1
+ module Panelbeater
2
2
  module Cpanel
3
3
  module Commands
4
4
 
@@ -1,4 +1,4 @@
1
- module CpanelApi
1
+ module Panelbeater
2
2
  class FixtureHelper
3
3
 
4
4
  def self.load(name)
@@ -1,4 +1,4 @@
1
- module CpanelApi
1
+ module Panelbeater
2
2
  module Model
3
3
 
4
4
  def key_mappings(map, hash)
@@ -1,4 +1,4 @@
1
- module CpanelApi
1
+ module Panelbeater
2
2
  module Remote
3
3
 
4
4
  @@default_port = 2087
@@ -25,7 +25,7 @@ module CpanelApi
25
25
  options = key_mappings(mappings, options) unless mappings.nil?
26
26
  options = filter_options(options)
27
27
  response = connect self.base_url, self.port, command, self.user, self.api_key, options
28
- CpanelApi::Response.new(command, response)
28
+ Panelbeater::Response.new(command, response)
29
29
  end
30
30
 
31
31
  def map_options_to_url(options={})
@@ -1,10 +1,14 @@
1
- module CpanelApi
1
+ module Panelbeater
2
2
  class Response
3
3
 
4
4
  @@response_types = {
5
- :applist => 'app',
6
- :createacct => 'result',
7
- :passwd => 'passwd'
5
+ :applist => 'app',
6
+ :createacct => 'result',
7
+ :changepackage => 'result',
8
+ :passwd => 'passwd',
9
+ :suspendacct => 'result',
10
+ :unsuspendacct => 'result',
11
+ :removeacct => 'result'
8
12
  }
9
13
 
10
14
  def initialize(command, response)
@@ -13,7 +17,7 @@ module CpanelApi
13
17
  end
14
18
 
15
19
  def success?
16
- json[node_name].first['status'] == 1
20
+ self.status == 1
17
21
  end
18
22
 
19
23
  def code
@@ -26,7 +30,11 @@ module CpanelApi
26
30
 
27
31
  def method_missing(method, *args)
28
32
  # check for a key in the json response
29
- return(json[node_name].first[method.to_s]) if json[node_name].first.has_key?(method.to_s)
33
+ if json[node_name].respond_to? 'first'
34
+ if json[node_name].first.respond_to?('has_key?') && json[node_name].first.has_key?(method.to_s)
35
+ json[node_name].first[method.to_s]
36
+ end
37
+ end
30
38
  end
31
39
 
32
40
  private
@@ -1,4 +1,4 @@
1
- module CpanelApi
1
+ module Panelbeater
2
2
  module Whm
3
3
  class Commands
4
4
  include Model
data/panelbeater.gemspec CHANGED
@@ -2,18 +2,18 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{panelbeater}
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jamie Dyer"]
9
9
  s.date = %q{2010-04-05}
10
10
  s.email = %q{jamie@kernowsoul.com}
11
- s.files = ["lib", "lib/panelbeater", "lib/panelbeater/cpanel", "lib/panelbeater/cpanel/commands.rb", "lib/panelbeater/fixture_helper.rb", "lib/panelbeater/model.rb", "lib/panelbeater/remote.rb", "lib/panelbeater/response.rb", "lib/panelbeater/whm", "lib/panelbeater/whm/commands.rb", "lib/panelbeater.rb", "panelbeater.gemspec", "pkg", "pkg/panelbeater-0.1.0.gem", "pkg/panelbeater-0.1.1.gem", "pkg/panelbeater-0.1.2.gem", "Rakefile", "Readme.markdown", "test", "test/fixtures", "test/fixtures/applist.json", "test/fixtures/createacct_fail.json", "test/fixtures/createacct_success.json", "test/fixtures/passwd_fail.json", "test/fixtures/passwd_success.json", "test/test_helper.rb", "test/whm_test.rb", "~"]
11
+ s.files = ["lib", "lib/panelbeater", "lib/panelbeater/cpanel", "lib/panelbeater/cpanel/commands.rb", "lib/panelbeater/fixture_helper.rb", "lib/panelbeater/model.rb", "lib/panelbeater/remote.rb", "lib/panelbeater/response.rb", "lib/panelbeater/whm", "lib/panelbeater/whm/commands.rb", "lib/panelbeater.rb", "panelbeater.gemspec", "pkg", "pkg/panelbeater-0.1.0.gem", "pkg/panelbeater-0.1.1.gem", "pkg/panelbeater-0.1.2.gem", "pkg/panelbeater-0.1.3.gem", "Rakefile", "Readme.markdown", "test", "test/fixtures", "test/fixtures/applist.json", "test/fixtures/changepackage_fail.json", "test/fixtures/changepackage_success.json", "test/fixtures/createacct_fail.json", "test/fixtures/createacct_success.json", "test/fixtures/passwd_fail.json", "test/fixtures/passwd_success.json", "test/fixtures/removeacct_fail.json", "test/fixtures/removeacct_success.json", "test/fixtures/suspendacct_fail.json", "test/fixtures/suspendacct_success.json", "test/fixtures/unsuspendacct_fail.json", "test/fixtures/unsuspendacct_success.json", "test/test_helper.rb", "test/whm_test.rb", "~"]
12
12
  s.homepage = %q{http://kernowsoul.com}
13
13
  s.require_paths = ["lib"]
14
14
  s.rubygems_version = %q{1.3.6}
15
15
  s.summary = %q{A gem for communicating with the cPanel and WHM API's}
16
- s.test_files = ["test/fixtures/applist.json", "test/fixtures/createacct_fail.json", "test/fixtures/createacct_success.json", "test/fixtures/passwd_fail.json", "test/fixtures/passwd_success.json", "test/test_helper.rb", "test/whm_test.rb"]
16
+ s.test_files = ["test/fixtures/applist.json", "test/fixtures/changepackage_fail.json", "test/fixtures/changepackage_success.json", "test/fixtures/createacct_fail.json", "test/fixtures/createacct_success.json", "test/fixtures/passwd_fail.json", "test/fixtures/passwd_success.json", "test/fixtures/removeacct_fail.json", "test/fixtures/removeacct_success.json", "test/fixtures/suspendacct_fail.json", "test/fixtures/suspendacct_success.json", "test/fixtures/unsuspendacct_fail.json", "test/fixtures/unsuspendacct_success.json", "test/test_helper.rb", "test/whm_test.rb"]
17
17
 
18
18
  if s.respond_to? :specification_version then
19
19
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
Binary file
@@ -0,0 +1 @@
1
+ {"result":[{"status":0,"statusmsg":"Sorry you may not create any more accounts with the package one.","rawout":null}]}
@@ -0,0 +1 @@
1
+ {"result":[{"status":1,"statusmsg":"Account Upgrade/Downgrade Complete for sdflkhds","rawout":"<pre>\nChanging bwlimit to unlimited Meg\nChanging Feature List to default\nChanging max pop accounts from unlimited to unlimited\nChanging max sql accounts from unlimited to unlimited\nChanging max ftp accounts from unlimited to unlimited\nChanging max lists from unlimited to unlimited\nChanging max sub domains from unlimited to unlimited\nChanging language from en to en\nChanging max parked domains from 0 to 0\nChanging max addon domains from 0 to 0\nShell Access Set Correctly\nChanging cPanel theme from x3 to x3\nChanging plan from a_package to a_package\nResetting QUOTA....\nUsing Quota v3 Support\nBandwidth limit (0) is lower than (unlimited) (all limits removed)<br /><blockquote><div style='float:left;'>Enabling...</div><div style='float:left;'>...sdfsdf.com...</div><div style='float:left;'>Done</div></blockquote><br /><div class='clearit' style='clear:both; width:80%;'>&nbsp;</div><span class=\"b2\">Warning, this will not cause ip-less accounts to become ip access, or the reverse.</span>\n"}]}
@@ -0,0 +1 @@
1
+ {"result":[{"status":0,"statusmsg":"Warning!.. system user amos does not exist!\n","rawout":null}]}
@@ -0,0 +1 @@
1
+ {"result":[{"status":1,"statusmsg":"amos account removed","rawout":"Running pre removal script (/scripts/prekillacct)......DoneCollecting Domain Name and IP...User: sdflkhds\nDomain: amod.com\n...DoneKilling all processes owned by user......DoneCleaning passwd,shadow,group......DoneRemoving User from Group..........DoneRemoving Web Logs......DoneRemoving Bandwidth Files......DoneRemoving Crontab......DoneRemoving Virtual Hosts...Removed amod.com Server at line: 423.\nRemoved Entry from httpd.conf\n...DoneRemoving MySQL databases and users......DoneRemoving PostgreSQL databases and users......DoneRemoving System User......DoneRemoving Group......DoneRemoving DNS Entries...amod.com => deleted from soltest. \n...DoneRemoving Email Setup...Removing /etc/valiases/amod.com\n...DoneRemoving mailman lists......DoneUpdating Databases......DoneRemoving Counter Data......DoneAdding ip back to the ip address pool...System has 0 free ips.\n...DoneRemoving user's cPanel Databases & Updating......DoneReloading Services......DoneRemoving mail and service configs...\n...DoneSending Contacts......DoneUpdating internal databases...Updating ftp passwords for sdflkhds\nPurging ftp user sdflkhds\nFtp password files updated.\nFtp vhost passwords synced\n...DoneRunning post removal scripts (/scripts/legacypostkillacct, /scripts/postkillacct)......DoneAccount Removal Complete!!!...sdflkhds account removed...Done"}]}
@@ -0,0 +1 @@
1
+ {"result":[{"status":0,"statusmsg":"_suspendacct called for a user that does not exist. (bobbie)"}]}
@@ -0,0 +1 @@
1
+ {"result":[{"status":1,"statusmsg":"<script>if (self['clear_ui_status']) { clear_ui_status(); }</script>\nChanging Shell to /bin/false...Changing shell for sdflkhds.\nWarning: \"/bin/false\" is not listed in /etc/shells\nShell changed.\nDone\nLocking Password...Locking password for user sdflkhds.\npasswd: Success\nDone\nSuspending mysql users\nNotification => tom@krystal.co.uk via EMAIL [level => 3]\nUsing Quota v3 Support\nSuspended document root /home/sdflkhds/public_html\nUsing Quota v3 Support\nSuspending FTP accounts...\nUpdating ftp passwords for sdflkhds\nFtp password files updated.\nFtp vhost passwords synced\nsdflkhds's account has been suspended\n"}]}
@@ -0,0 +1 @@
1
+ {"result":[{"status":0,"statusmsg":"_unsuspendacct called for a user that does not exist. (bobbie)"}]}
@@ -0,0 +1 @@
1
+ {"result":[{"status":1,"statusmsg":"<script>if (self['clear_ui_status']) { clear_ui_status(); }</script>\nChanging shell for sdflkhds.\nShell changed.\nUnlocking password for user sdflkhds.\npasswd: Success.\nUnsuspending FTP accounts...\nUpdating ftp passwords for sdflkhds\nFtp password files updated.\nFtp vhost passwords synced\nsdflkhds's account is now active\nUnsuspending mysql users\nNotification => tom@krystal.co.uk via EMAIL [level => 3]\n"}]}
data/test/whm_test.rb CHANGED
@@ -4,9 +4,10 @@ require "test_helper"
4
4
  class WhmTest < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
+ reset_webmock
7
8
  @expected_url = 'https://cpanel.server.local:2087/json-api/'
8
9
  @expected_auth_header = "WHM root:12345678"
9
- @connection = CpanelApi::Whm::Commands.new({ :url => 'cpanel.server.local', :api_key => "1234\r5678" })
10
+ @connection = Panelbeater::Whm::Commands.new({ :url => 'cpanel.server.local', :api_key => "1234\r5678" })
10
11
  end
11
12
 
12
13
 
@@ -49,6 +50,18 @@ class WhmTest < Test::Unit::TestCase
49
50
  end
50
51
  end
51
52
 
53
+ context "running a request with key mappings" do
54
+ setup do
55
+ stub_request(:any, /.*/)
56
+ @response = @connection.createacct({ :krazy => 'amos' }, { :krazy => :username })
57
+ end
58
+
59
+ should "send the request with the keys mapped correctly" do
60
+ assert_requested :get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n",
61
+ :headers => { 'Authorization' => @expected_auth_header }
62
+ end
63
+ end
64
+
52
65
  context "getting cpanel data from the cpanel response" do
53
66
  setup do
54
67
  stub_request(:get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n").
@@ -73,45 +86,284 @@ class WhmTest < Test::Unit::TestCase
73
86
  should "return a list of commands" do
74
87
  assert_equal JSON.parse(fixture('applist')), @response.json
75
88
  end
89
+
90
+ should "return the request was successful" do
91
+ # there is no 'status' message returned with an applist request so success? should return false
92
+ assert !@response.success?
93
+ end
76
94
  end
77
95
 
78
96
  context "creating a new account" do
79
- setup do
80
- stub_request(:get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n").
81
- with(:headers => { 'Authorization' => @expected_auth_header }).
82
- to_return(:body => fixture('createacct_success'))
83
- @response = @connection.createacct :username => 'amos'
97
+
98
+ context "successfully" do
99
+ setup do
100
+ stub_request(:get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n").
101
+ with(:headers => { 'Authorization' => @expected_auth_header }).
102
+ to_return(:body => fixture('createacct_success'))
103
+ @response = @connection.createacct :username => 'amos'
104
+ end
105
+
106
+ should "return the json object" do
107
+ assert_equal JSON.parse(fixture('createacct_success')), @response.json
108
+ end
109
+
110
+ should "return the request was successful" do
111
+ assert @response.success?
112
+ end
113
+
114
+ should "return the status message" do
115
+ assert_equal 'Account Creation Ok', @response.statusmsg
116
+ end
84
117
  end
118
+
119
+ context "unsuccessfully" do
120
+ setup do
121
+ stub_request(:get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n").
122
+ with(:headers => { 'Authorization' => @expected_auth_header }).
123
+ to_return(:body => fixture('createacct_fail'))
124
+ @response = @connection.createacct :username => 'amos'
125
+ end
85
126
 
86
- should "return a list of commands" do
87
- assert_equal JSON.parse(fixture('createacct_success')), @response.json
127
+ should "return the json object" do
128
+ assert_equal JSON.parse(fixture('createacct_fail')), @response.json
129
+ end
130
+
131
+ should "return the request was successful" do
132
+ assert !@response.success?
133
+ end
134
+
135
+ should "return the status message" do
136
+ assert_equal "Sorry, that's an invalid domain\n", @response.statusmsg
137
+ end
88
138
  end
89
139
  end
90
140
 
91
- context "creating a new account with key mappings" do
92
- setup do
93
- stub_request(:get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n").
94
- with(:headers => { 'Authorization' => @expected_auth_header }).
95
- to_return(:body => fixture('createacct_success'))
96
- @response = @connection.createacct({ :krazy => 'amos' }, { :krazy => :username })
141
+ context "changing a users package" do
142
+
143
+ context "successfully" do
144
+ setup do
145
+ stub_request(:get, "#{@expected_url}changepackage?pkg=new_package&user=amos").
146
+ with(:headers => { 'Authorization' => @expected_auth_header }).
147
+ to_return(:body => fixture('changepackage_success'))
148
+ @response = @connection.changepackage 'amos', 'new_package'
149
+ end
150
+
151
+ should "return the json object" do
152
+ assert_equal JSON.parse(fixture('changepackage_success')), @response.json
153
+ end
154
+
155
+ should "return the request was successful" do
156
+ assert @response.success?
157
+ end
158
+
159
+ should "return the status message" do
160
+ assert_equal 'Account Upgrade/Downgrade Complete for sdflkhds', @response.statusmsg
161
+ end
97
162
  end
163
+
164
+ context "unsuccessfully" do
165
+ setup do
166
+ stub_request(:get, "#{@expected_url}changepackage?pkg=new_package&user=amos").
167
+ with(:headers => { 'Authorization' => @expected_auth_header }).
168
+ to_return(:body => fixture('changepackage_fail'))
169
+ @response = @connection.changepackage 'amos', 'new_package'
170
+ end
98
171
 
99
- should "return a list of commands" do
100
- assert_equal JSON.parse(fixture('createacct_success')), @response.json
172
+ should "return the json object" do
173
+ assert_equal JSON.parse(fixture('changepackage_fail')), @response.json
174
+ end
175
+
176
+ should "return the request was successful" do
177
+ assert !@response.success?
178
+ end
179
+
180
+ should "return the status message" do
181
+ assert_equal 'Sorry you may not create any more accounts with the package one.', @response.statusmsg
182
+ end
101
183
  end
102
184
  end
103
185
 
104
186
  context "changing a users password" do
105
- setup do
106
- stub_request(:get, "#{@expected_url}passwd?user=bob&pass=hello").
107
- with(:headers => { 'Authorization' => @expected_auth_header }).
108
- to_return(:body => fixture('passwd_success'))
109
- @response = @connection.passwd('bob', 'hello')
187
+
188
+ context "successfully" do
189
+ setup do
190
+ stub_request(:get, "#{@expected_url}passwd?user=bob&pass=hello").
191
+ with(:headers => { 'Authorization' => @expected_auth_header }).
192
+ to_return(:body => fixture('passwd_success'))
193
+ @response = @connection.passwd('bob', 'hello')
194
+ end
195
+
196
+ should "return a list of commands" do
197
+ assert_equal JSON.parse(fixture('passwd_success')), @response.json
198
+ end
199
+
200
+ should "return the request was successful" do
201
+ assert @response.success?
202
+ end
203
+
204
+ should "return the status message" do
205
+ assert_equal 'Password changed for user bob', @response.statusmsg
206
+ end
110
207
  end
208
+
209
+ context "unsuccessfully" do
210
+ setup do
211
+ stub_request(:get, "#{@expected_url}passwd?user=bob&pass=hello").
212
+ with(:headers => { 'Authorization' => @expected_auth_header }).
213
+ to_return(:body => fixture('passwd_fail'))
214
+ @response = @connection.passwd('bob', 'hello')
215
+ end
111
216
 
112
- should "return a list of commands" do
113
- assert_equal JSON.parse(fixture('passwd_success')), @response.json
217
+ should "return a list of commands" do
218
+ assert_equal JSON.parse(fixture('passwd_fail')), @response.json
219
+ end
220
+
221
+ should "return the request was successful" do
222
+ assert !@response.success?
223
+ end
224
+
225
+ should "return the status message" do
226
+ assert_equal 'Sorry, the user bob2 does not exist.', @response.statusmsg
227
+ end
228
+ end
229
+ end
230
+
231
+ context "suspending a users account" do
232
+
233
+ context "successfully" do
234
+ setup do
235
+ stub_request(:get, "#{@expected_url}suspendacct?reason=non%20payment%20of%20bill&user=amos").
236
+ with(:headers => { 'Authorization' => @expected_auth_header }).
237
+ to_return(:body => fixture('suspendacct_success'))
238
+ @response = @connection.suspendacct 'amos', 'non payment of bill'
239
+ end
240
+
241
+ should "return the json object" do
242
+ assert_equal JSON.parse(fixture('suspendacct_success')), @response.json
243
+ end
244
+
245
+ should "return the request was successful" do
246
+ assert @response.success?
247
+ end
248
+
249
+ should "return the status message" do
250
+ # yes the WHM API really does return this kind of crap as the status message
251
+ assert_equal "<script>if (self['clear_ui_status']) { clear_ui_status(); }</script>\nChanging Shell to /bin/false...Changing shell for sdflkhds.\nWarning: \"/bin/false\" is not listed in /etc/shells\nShell changed.\nDone\nLocking Password...Locking password for user sdflkhds.\npasswd: Success\nDone\nSuspending mysql users\nNotification => tom@krystal.co.uk via EMAIL [level => 3]\nUsing Quota v3 Support\nSuspended document root /home/sdflkhds/public_html\nUsing Quota v3 Support\nSuspending FTP accounts...\nUpdating ftp passwords for sdflkhds\nFtp password files updated.\nFtp vhost passwords synced\nsdflkhds's account has been suspended\n", @response.statusmsg
252
+ end
253
+ end
254
+
255
+ context "unsuccessfully" do
256
+ setup do
257
+ stub_request(:get, "#{@expected_url}suspendacct?reason=non%20payment%20of%20bill&user=amos").
258
+ with(:headers => { 'Authorization' => @expected_auth_header }).
259
+ to_return(:body => fixture('suspendacct_fail'))
260
+ @response = @connection.suspendacct 'amos', 'non payment of bill'
261
+ end
262
+
263
+ should "return the json object" do
264
+ assert_equal JSON.parse(fixture('suspendacct_fail')), @response.json
265
+ end
266
+
267
+ should "return the request was unsuccessful" do
268
+ assert !@response.success?
269
+ end
270
+
271
+ should "return the status message" do
272
+ assert_equal "_suspendacct called for a user that does not exist. (bobbie)", @response.statusmsg
273
+ end
274
+ end
275
+
276
+ end
277
+
278
+ context "unsuspending a users account" do
279
+
280
+ context "successfully" do
281
+ setup do
282
+ stub_request(:get, "#{@expected_url}unsuspendacct?user=amos").
283
+ with(:headers => { 'Authorization' => @expected_auth_header }).
284
+ to_return(:body => fixture('unsuspendacct_success'))
285
+ @response = @connection.unsuspendacct 'amos'
286
+ end
287
+
288
+ should "return the json object" do
289
+ assert_equal JSON.parse(fixture('unsuspendacct_success')), @response.json
290
+ end
291
+
292
+ should "return the request was successful" do
293
+ assert @response.success?
294
+ end
295
+
296
+ should "return the status message" do
297
+ assert_equal "<script>if (self['clear_ui_status']) { clear_ui_status(); }</script>\nChanging shell for sdflkhds.\nShell changed.\nUnlocking password for user sdflkhds.\npasswd: Success.\nUnsuspending FTP accounts...\nUpdating ftp passwords for sdflkhds\nFtp password files updated.\nFtp vhost passwords synced\nsdflkhds's account is now active\nUnsuspending mysql users\nNotification => tom@krystal.co.uk via EMAIL [level => 3]\n", @response.statusmsg
298
+ end
114
299
  end
300
+
301
+ context "unsuccessfully" do
302
+ setup do
303
+ stub_request(:get, "#{@expected_url}unsuspendacct?user=amos").
304
+ with(:headers => { 'Authorization' => @expected_auth_header }).
305
+ to_return(:body => fixture('unsuspendacct_fail'))
306
+ @response = @connection.unsuspendacct 'amos'
307
+ end
308
+
309
+ should "return the json object" do
310
+ assert_equal JSON.parse(fixture('unsuspendacct_fail')), @response.json
311
+ end
312
+
313
+ should "return the request was unsuccessful" do
314
+ assert !@response.success?
315
+ end
316
+
317
+ should "return the status message" do
318
+ assert_equal "_unsuspendacct called for a user that does not exist. (bobbie)", @response.statusmsg
319
+ end
320
+ end
321
+
115
322
  end
323
+
324
+ context "removing a users account" do
325
+
326
+ context "successfully" do
327
+ setup do
328
+ stub_request(:get, "#{@expected_url}removeacct?keepdns=0&user=amos").
329
+ with(:headers => { 'Authorization' => @expected_auth_header }).
330
+ to_return(:body => fixture('removeacct_success'))
331
+ @response = @connection.removeacct 'amos'
332
+ end
333
+
334
+ should "return the json object" do
335
+ assert_equal JSON.parse(fixture('removeacct_success')), @response.json
336
+ end
116
337
 
338
+ should "return the request was successful" do
339
+ assert @response.success?
340
+ end
341
+
342
+ should "return the status message" do
343
+ assert_equal "amos account removed", @response.statusmsg
344
+ end
345
+ end
346
+
347
+ context "unsuccessfully" do
348
+ setup do
349
+ stub_request(:get, "#{@expected_url}removeacct?keepdns=0&user=amos").
350
+ with(:headers => { 'Authorization' => @expected_auth_header }).
351
+ to_return(:body => fixture('removeacct_fail'))
352
+ @response = @connection.removeacct 'amos'
353
+ end
354
+
355
+ should "return the json object" do
356
+ assert_equal JSON.parse(fixture('removeacct_fail')), @response.json
357
+ end
358
+
359
+ should "return the request was unsuccessful" do
360
+ assert !@response.success?
361
+ end
362
+
363
+ should "return the status message" do
364
+ assert_equal "Warning!.. system user amos does not exist!\n", @response.statusmsg
365
+ end
366
+ end
367
+ end
368
+
117
369
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jamie Dyer
@@ -73,13 +73,22 @@ files:
73
73
  - pkg/panelbeater-0.1.0.gem
74
74
  - pkg/panelbeater-0.1.1.gem
75
75
  - pkg/panelbeater-0.1.2.gem
76
+ - pkg/panelbeater-0.1.3.gem
76
77
  - Rakefile
77
78
  - Readme.markdown
78
79
  - test/fixtures/applist.json
80
+ - test/fixtures/changepackage_fail.json
81
+ - test/fixtures/changepackage_success.json
79
82
  - test/fixtures/createacct_fail.json
80
83
  - test/fixtures/createacct_success.json
81
84
  - test/fixtures/passwd_fail.json
82
85
  - test/fixtures/passwd_success.json
86
+ - test/fixtures/removeacct_fail.json
87
+ - test/fixtures/removeacct_success.json
88
+ - test/fixtures/suspendacct_fail.json
89
+ - test/fixtures/suspendacct_success.json
90
+ - test/fixtures/unsuspendacct_fail.json
91
+ - test/fixtures/unsuspendacct_success.json
83
92
  - test/test_helper.rb
84
93
  - test/whm_test.rb
85
94
  has_rdoc: true
@@ -114,9 +123,17 @@ specification_version: 3
114
123
  summary: A gem for communicating with the cPanel and WHM API's
115
124
  test_files:
116
125
  - test/fixtures/applist.json
126
+ - test/fixtures/changepackage_fail.json
127
+ - test/fixtures/changepackage_success.json
117
128
  - test/fixtures/createacct_fail.json
118
129
  - test/fixtures/createacct_success.json
119
130
  - test/fixtures/passwd_fail.json
120
131
  - test/fixtures/passwd_success.json
132
+ - test/fixtures/removeacct_fail.json
133
+ - test/fixtures/removeacct_success.json
134
+ - test/fixtures/suspendacct_fail.json
135
+ - test/fixtures/suspendacct_success.json
136
+ - test/fixtures/unsuspendacct_fail.json
137
+ - test/fixtures/unsuspendacct_success.json
121
138
  - test/test_helper.rb
122
139
  - test/whm_test.rb