qbt_client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,642 @@
1
+ require 'spec_helper'
2
+ include QbtClient
3
+
4
+ describe WebUI do
5
+
6
+ after(:all) do
7
+ delete_all_torrents
8
+ sleep 1
9
+ end
10
+
11
+ context "#torrent_list" do
12
+
13
+ it "returns array of torrents" do
14
+ hash, name = given_a_paused_downloading_torrent
15
+
16
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
17
+ list = client.torrent_list
18
+
19
+ expect(list.class).to eq Array
20
+ expect(list[0]['dlspeed']).to_not eq nil
21
+ end
22
+ end
23
+
24
+ context "#torrent_data" do
25
+
26
+ it "returns data for a specific torrent in Hash object" do
27
+ hash, name = given_a_paused_downloading_torrent
28
+
29
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
30
+ data = client.torrent_data hash
31
+
32
+ expect(data.class).to eq Hash
33
+ expect(data["name"].include?(name)).to eq true
34
+ end
35
+ end
36
+
37
+ context "#properties" do
38
+
39
+ it "returns torrent properties in Hash object" do
40
+ hash, name = given_a_paused_downloading_torrent
41
+ sleep 1
42
+
43
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
44
+ res = client.properties hash
45
+
46
+ expect(res.class).to eq Hash
47
+ expect(res['save_path']).to_not eq nil
48
+ end
49
+ end
50
+
51
+ context "#trackers" do
52
+
53
+ it "returns tracker data in Array of Hashes" do
54
+ hash, name = given_a_paused_downloading_torrent
55
+
56
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
57
+ res = client.trackers hash
58
+
59
+ expect(res.class).to eq Array
60
+ expect(res[0].class).to eq Hash
61
+ expect(res[0]['msg']).to_not eq nil
62
+ expect(res[0]['status']).to_not eq nil
63
+ expect(res[0]['url']).to_not eq nil
64
+ end
65
+ end
66
+
67
+ context "#add_trackers" do
68
+
69
+ it "add one tracker to a torrent" do
70
+ hash, name = given_a_paused_downloading_torrent
71
+
72
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
73
+ trackers = client.trackers hash
74
+ tcount = trackers.count
75
+
76
+ url = 'http://announce.tracker.com'
77
+
78
+ client.add_trackers hash, url
79
+ sleep 2
80
+
81
+ trackers = client.trackers hash
82
+ expect(trackers.count).to eq (tcount + 1)
83
+
84
+ expect(trackers[tcount]['url']).to eq url
85
+ end
86
+
87
+ it "add multiple trackers to a torrent" do
88
+ hash, name = given_a_paused_downloading_torrent
89
+
90
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
91
+ trackers = client.trackers hash
92
+ tcount = trackers.count
93
+
94
+ url1 = 'http://announce.tracker.com:1000'
95
+ url2 = 'http://announce.tracker.com:2000'
96
+ url3 = 'http://announce.tracker.com:3000'
97
+
98
+ client.add_trackers hash, [url1, url2, url3]
99
+ sleep 2
100
+
101
+ trackers = client.trackers hash
102
+ expect(trackers.count).to eq (tcount + 3)
103
+
104
+ expect(trackers[tcount]['url']).to eq url1
105
+ expect(trackers[tcount+1]['url']).to eq url2
106
+ expect(trackers[tcount+2]['url']).to eq url3
107
+ end
108
+
109
+ it "ampersands in tracker urls are escaped" do
110
+ hash, name = given_a_paused_downloading_torrent
111
+
112
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
113
+ trackers = client.trackers hash
114
+ tcount = trackers.count
115
+
116
+ url1 = 'http://announce.tracker.com:1000?blah&blah'
117
+ url2 = 'http://announce.tracker.com:2000?foo&foo'
118
+ url3 = 'http://announce.tracker.com:3000?bar&bar'
119
+
120
+ client.add_trackers hash, [url1, url2, url3]
121
+ sleep 2
122
+
123
+ trackers = client.trackers hash
124
+ expect(trackers.count).to eq (tcount + 3)
125
+
126
+ expect(trackers[tcount]['url']).to eq url1
127
+ expect(trackers[tcount+1]['url']).to eq url2
128
+ expect(trackers[tcount+2]['url']).to eq url3
129
+ end
130
+ end
131
+
132
+ context "#contents" do
133
+
134
+ it "returns Array of Hashes, one for each file in torrent" do
135
+ hash, name = given_a_paused_downloading_torrent
136
+
137
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
138
+ res = client.contents hash
139
+
140
+ expect(res.class).to eq Array
141
+ expect(res[0].class).to eq Hash
142
+ expect(res[0]['is_seed']).to_not eq nil
143
+ expect(res[0]['name']).to_not eq nil
144
+ end
145
+ end
146
+
147
+ context "#transfer_info" do
148
+
149
+ it "returns hash" do
150
+ hash, name = given_a_paused_downloading_torrent
151
+
152
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
153
+ res = client.transfer_info
154
+
155
+ expect(res.class).to eq Hash
156
+ expect(res['dl_info']).to_not eq nil
157
+ expect(res['up_info']).to_not eq nil
158
+ end
159
+ end
160
+
161
+ context "#preferences" do
162
+
163
+ it "returns hash" do
164
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
165
+ res = client.preferences
166
+
167
+ expect(res.class).to eq Hash
168
+ expect(res['alt_dl_limit']).to_not eq nil
169
+ expect(res['alt_up_limit']).to_not eq nil
170
+ expect(res['save_path']).to_not eq nil
171
+ end
172
+ end
173
+
174
+ context "#set_preferences" do
175
+
176
+ let(:save_path) {
177
+ "/home/jeff/projects/ruby/qbittorrent/tmp/spec/client"
178
+ }
179
+
180
+ it "sets preferences when provided a valid hash" do
181
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
182
+ orig_save_path = client.preferences['save_path']
183
+
184
+ res = client.set_preferences({ "save_path"=>save_path })
185
+
186
+ # Read preferences back and verify update
187
+ res = client.preferences
188
+ expect(res["save_path"]).to eq save_path
189
+
190
+ # Set the save_path back to original value
191
+ res = client.set_preferences({ "save_path"=>orig_save_path })
192
+ end
193
+
194
+ it "fails when not provided a Hash" do
195
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
196
+ expect{ client.set_preferences("\"save_path\":\"#{save_path}\"") }.to raise_exception
197
+ end
198
+ end
199
+
200
+ context "#pause" do
201
+
202
+ it "pauses a torrent" do
203
+ hash, name = given_a_downloading_torrent
204
+
205
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
206
+ res = client.pause hash
207
+ # Give app a chance to update
208
+ sleep 2
209
+
210
+ data = client.torrent_data hash
211
+ expect(data["state"]).to eq 'pausedDL'
212
+ end
213
+ end
214
+
215
+ context "#pause_all" do
216
+
217
+ it "pauses all torrents" do
218
+ hash, name = given_a_downloading_torrent
219
+ hash2, name2 = given_another_downloading_torrent
220
+
221
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
222
+ res = client.pause_all
223
+ # Give app a chance to update
224
+ sleep 2
225
+
226
+ data = client.torrent_data hash
227
+ #print_response data
228
+ #puts "state: #{data["state"]}"
229
+
230
+ data2 = client.torrent_data hash2
231
+ #print_response data2
232
+ #puts "state: #{data2["state"]}"
233
+
234
+ expect(data["state"]).to eq 'pausedDL'
235
+ expect(data2["state"]).to eq 'pausedDL'
236
+ end
237
+ end
238
+
239
+ context "#resume" do
240
+
241
+ it "resumes a paused torrent" do
242
+ hash, name = given_a_paused_downloading_torrent
243
+
244
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
245
+ res = client.resume hash
246
+ # Give app a chance to update
247
+ sleep 2
248
+
249
+ data = client.torrent_data hash
250
+ state = data["state"]
251
+ state_is_expected = (state == 'stalledDL' or state == 'downloading')
252
+
253
+ expect(state_is_expected).to eq true
254
+ end
255
+ end
256
+
257
+ context "#resume_all" do
258
+
259
+ it "resumes all paused torrents" do
260
+ hash, name = given_a_paused_downloading_torrent
261
+ hash2, name2 = given_another_paused_downloading_torrent
262
+
263
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
264
+ res = client.resume_all
265
+ # Give app a chance to update
266
+ sleep 2
267
+
268
+ data = client.torrent_data hash
269
+ state = data["state"]
270
+ state_is_expected = (state == 'stalledDL' or state == 'downloading')
271
+
272
+ expect(state_is_expected).to eq true
273
+
274
+ data = client.torrent_data hash2
275
+ state = data["state"]
276
+ state_is_expected = (state == 'stalledDL' or state == 'downloading')
277
+
278
+ expect(state_is_expected).to eq true
279
+ end
280
+ end
281
+
282
+ context "#download" do
283
+
284
+ it "downloads a torrent" do
285
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
286
+
287
+ res = client.download test_torrent_url
288
+ # Give app a chance to update
289
+ sleep 2
290
+
291
+ # Verify torrent is downloading
292
+ expect(torrent_with_name_exists?(client, test_torrent_name)).to eq true
293
+
294
+ # Pause the download so we don't waste bandwidth
295
+ unless hash.nil?
296
+ client.pause hash
297
+ end
298
+ end
299
+ end
300
+
301
+ context "#upload" do
302
+
303
+ it "upload a torrent from disk" do
304
+ pending('implementation')
305
+ fail
306
+ end
307
+ end
308
+
309
+ context "#delete_torrent_and_data" do
310
+
311
+ it "deletes one or more torrents and their data" do
312
+ hash, name = given_a_paused_downloading_torrent
313
+
314
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
315
+
316
+ res = client.delete_torrent_and_data hash
317
+ # Give app a chance to update
318
+ sleep 2
319
+
320
+ # Verify torrent has been deleted
321
+ expect(torrent_exists?(client, hash)).to eq false
322
+ end
323
+ end
324
+
325
+ context "#delete" do
326
+
327
+ it "deletes one or more torrents, but not their data" do
328
+ hash, name = given_a_paused_downloading_torrent
329
+
330
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
331
+
332
+ res = client.delete hash
333
+ # Give app a chance to update
334
+ sleep 2
335
+
336
+ # Verify torrent has been deleted
337
+ expect(torrent_exists?(client, hash)).to eq false
338
+ end
339
+ end
340
+
341
+ context "#recheck" do
342
+
343
+ it "rechecks a torrent" do
344
+ hash, name = given_a_downloading_torrent
345
+ # Pause so the download can get going.
346
+ sleep 5
347
+
348
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
349
+
350
+ res = client.recheck hash
351
+ # Give app a chance to update
352
+ sleep 2
353
+
354
+ data = client.torrent_data hash
355
+ state = data["state"]
356
+ #puts "State: #{data['state']}"
357
+ state_is_expected = (state == 'checkingDL' or state == 'checkingUP')
358
+
359
+ expect(state_is_expected).to eq true
360
+ end
361
+ end
362
+
363
+ context "#increase_priority" do
364
+
365
+ it "increase torrent(s) queue priority(s)" do
366
+ hash, name = given_a_downloading_torrent
367
+ hash2, name2 = given_another_downloading_torrent
368
+
369
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
370
+
371
+ # Turn on queueing or priority is always '*'.
372
+ enable_queueing client, true
373
+ sleep 2
374
+
375
+ # Get initial priority.
376
+ prio = get_torrent_info client, hash2, 'priority'
377
+
378
+ # Increase the priority.
379
+ client.increase_priority hash2
380
+ sleep 2
381
+
382
+ # Verify it got better (lower number).
383
+ prio_after_increase = get_torrent_info client, hash2, 'priority'
384
+
385
+ # Turn queueing back off.
386
+ enable_queueing client, false
387
+
388
+ expect(prio_after_increase < prio).to eq true
389
+ end
390
+ end
391
+
392
+ context "#decrease_priority" do
393
+
394
+ it "decrease torrent(s) queue priority(s)" do
395
+ hash, name = given_a_downloading_torrent
396
+ hash2, name2 = given_another_downloading_torrent
397
+
398
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
399
+
400
+ # Turn on queueing or priority is always '*'.
401
+ enable_queueing client, true
402
+ sleep 2
403
+
404
+ # Get initial priority.
405
+ prio = get_torrent_info client, hash, 'priority'
406
+
407
+ # Decrease the priority.
408
+ client.decrease_priority hash
409
+ sleep 2
410
+
411
+ # Verify it got worse (higher number).
412
+ prio_after_decrease = get_torrent_info client, hash, 'priority'
413
+
414
+ # Turn queueing back off.
415
+ enable_queueing client, false
416
+
417
+ expect(prio_after_decrease > prio).to eq true
418
+ end
419
+ end
420
+
421
+ context "#maximize_priority" do
422
+
423
+ it "maximize torrent(s) queue priority(s)" do
424
+ hash, name = given_a_downloading_torrent
425
+ hash2, name2 = given_another_downloading_torrent
426
+
427
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
428
+
429
+ # Turn on queueing or priority is always '*'.
430
+ enable_queueing client, true
431
+ sleep 2
432
+
433
+ # Get initial priority.
434
+ prio = get_torrent_info client, hash2, 'priority'
435
+
436
+ # Maximize the priority.
437
+ client.maximize_priority hash2
438
+ sleep 2
439
+
440
+ # Verify it was maximized (priority = 1)
441
+ prio_after_increase = get_torrent_info client, hash2, 'priority'
442
+
443
+ # Turn queueing back off.
444
+ enable_queueing client, false
445
+
446
+ expect(prio_after_increase == '1').to eq true
447
+ end
448
+ end
449
+
450
+ context "#minimize_priority" do
451
+
452
+ it "minimize torrent(s) queue priority(s)" do
453
+ hash, name = given_a_downloading_torrent
454
+ hash2, name2 = given_another_downloading_torrent
455
+
456
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
457
+
458
+ # Turn on queueing or priority is always '*'.
459
+ enable_queueing client, true
460
+ sleep 2
461
+
462
+ # Get initial priority.
463
+ prio = get_torrent_info client, hash, 'priority'
464
+
465
+ # Minimize the priority.
466
+ client.minimize_priority hash
467
+ sleep 2
468
+
469
+ # Verify it was minimized (priority = 2, because there are only 2 torrents active)
470
+ prio_after_decrease = get_torrent_info client, hash, 'priority'
471
+
472
+ # Turn queueing back off.
473
+ enable_queueing client, false
474
+
475
+ expect(prio_after_decrease == '2').to eq true
476
+ end
477
+ end
478
+
479
+ context "#set_file_priority" do
480
+
481
+ it "set a file's priority (within a torrent)" do
482
+ hash, name = given_a_paused_downloading_torrent
483
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
484
+ files = client.contents hash
485
+
486
+ # Set priority for each file in torrent.
487
+ # Priority will equal its position +1.
488
+ files.each_with_index do |f,i|
489
+ client.set_file_priority hash, i, (i+1)
490
+ end
491
+ sleep 2
492
+
493
+ # Verify each file's priority matches its position +1
494
+ files = client.contents hash
495
+ files.each_with_index do |f,i|
496
+ prio = i + 1
497
+ expect( f['priority'] == prio ).to eq true
498
+ end
499
+
500
+ # Clean up
501
+ client.delete_torrent_and_data hash
502
+ end
503
+ end
504
+
505
+ context "#global_download_limit" do
506
+
507
+ it "return the global download limit in bytes" do
508
+ hash, name = given_a_paused_downloading_torrent
509
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
510
+ limit = client.global_download_limit
511
+
512
+ expect(limit.integer?).to eq true
513
+ end
514
+ end
515
+
516
+ context "#set_global_download_limit" do
517
+
518
+ it "set the global download limit in bytes" do
519
+ hash, name = given_a_paused_downloading_torrent
520
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
521
+ old_limit = client.global_download_limit
522
+
523
+ expected_limit = 1000
524
+ client.set_global_download_limit expected_limit
525
+
526
+ actual_limit = client.global_download_limit
527
+
528
+ expect(expected_limit == actual_limit).to eq true
529
+
530
+ # Clean up
531
+ client.set_global_download_limit old_limit
532
+ end
533
+ end
534
+
535
+ context "#global_upload_limit" do
536
+
537
+ it "return the global upload limit in bytes" do
538
+ hash, name = given_a_paused_downloading_torrent
539
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
540
+ limit = client.global_upload_limit
541
+
542
+ expect(limit.integer?).to eq true
543
+ end
544
+ end
545
+
546
+ context "#set_global_upload_limit" do
547
+
548
+ it "set the global upload limit in bytes" do
549
+ hash, name = given_a_paused_downloading_torrent
550
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
551
+ old_limit = client.global_upload_limit
552
+
553
+ expected_limit = 1000
554
+ client.set_global_upload_limit expected_limit
555
+
556
+ actual_limit = client.global_upload_limit
557
+
558
+ expect(expected_limit == actual_limit).to eq true
559
+
560
+ # Clean up
561
+ client.set_global_upload_limit old_limit
562
+ end
563
+ end
564
+
565
+ context "#download_limit" do
566
+
567
+ it "return the torrent download limit in bytes" do
568
+ hash, name = given_a_paused_downloading_torrent
569
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
570
+ limit = client.download_limit hash
571
+
572
+ expect(limit.integer?).to eq true
573
+ end
574
+ end
575
+
576
+ context "#set_download_limit" do
577
+
578
+ it "set the torrent download limit in bytes" do
579
+ hash, name = given_a_paused_downloading_torrent
580
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
581
+ old_limit = client.download_limit hash
582
+
583
+ expected_limit = 1000
584
+ client.set_download_limit hash, expected_limit
585
+
586
+ actual_limit = client.download_limit hash
587
+
588
+ expect(expected_limit == actual_limit).to eq true
589
+
590
+ # Clean up
591
+ client.set_download_limit hash, old_limit
592
+ end
593
+ end
594
+
595
+ context "#upload_limit" do
596
+
597
+ it "return the torrent upload limit in bytes" do
598
+ hash, name = given_a_paused_downloading_torrent
599
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
600
+ limit = client.upload_limit hash
601
+
602
+ expect(limit.integer?).to eq true
603
+ end
604
+ end
605
+
606
+ context "#set_upload_limit" do
607
+
608
+ it "set the torrent upload limit in bytes" do
609
+ hash, name = given_a_paused_downloading_torrent
610
+ client = WebUI.new(test_ip, test_port, test_user, test_pass)
611
+ old_limit = client.upload_limit hash
612
+
613
+ expected_limit = 1000
614
+ client.set_upload_limit hash, expected_limit
615
+
616
+ actual_limit = client.upload_limit hash
617
+
618
+ expect(expected_limit == actual_limit).to eq true
619
+
620
+ # Clean up
621
+ client.set_upload_limit hash, old_limit
622
+ end
623
+ end
624
+
625
+ #context "test" do
626
+
627
+ # it "tests a torrent" do
628
+ # #hash, name = given_a_downloading_torrent
629
+
630
+
631
+ # client = WebUI.new(test_ip, test_port, test_user, test_pass)
632
+ # hash = hash_from_torrent_name client, test_torrent_name
633
+ # res = client.pause hash
634
+ # # Give app a chance to update
635
+ # sleep 2
636
+
637
+ # data = client.torrent_data hash
638
+ # print_response data
639
+ # #expect(data["state"]).to eq 'pausedDL'
640
+ # end
641
+ #end
642
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe QbtClient do
4
+ it 'has a version number' do
5
+ expect(QbtClient::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end