download_tv 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,184 +1,168 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  describe DownloadTV::Downloader do
4
- config_path = File.realdirpath("#{__dir__}/test_config")
5
-
6
- before do
7
- Dir.chdir(__dir__)
8
- create_dummy_config(config_path) unless File.exist?(config_path)
9
- end
10
-
11
- after do
12
- File.delete(config_path) if File.exist?(config_path)
13
- end
14
-
15
- describe "when creating the object" do
16
- it "should store the first argument as @offset" do
17
- DownloadTV::Downloader.new(3, path: config_path).offset.must_equal 3
18
- DownloadTV::Downloader.new(-3, path: config_path).offset.must_equal 3
19
- end
20
-
21
- it "should receive an integer for the offset" do
22
- ->{ DownloadTV::Downloader.new("foo") }.must_raise NoMethodError
23
- end
24
-
25
- it "can receive an optional configuration hash" do
26
- dl = DownloadTV::Downloader.new(0, auto: true, grabber: "KAT", path: config_path)
27
- dl.config[:auto].must_equal true
28
- dl.config[:grabber].must_equal "KAT"
29
- end
30
-
31
- end
32
-
33
- describe "the fix_names method" do
34
- it "should remove apostrophes, colons and parens" do
35
- shows = ["Mr. Foo S01E02", "Bar (UK) S00E22", "Let's S05E03", "Baz: The Story S05E22"]
36
- result = ["Mr. Foo S01E02", "Bar S00E22", "Lets S05E03", "Baz The Story S05E22"]
37
-
38
- dl = DownloadTV::Downloader.new(0, ignored: [], path: config_path)
39
- dl.fix_names(shows).must_equal result
40
- end
41
-
42
- it "should remove ignored shows" do
43
- shows = ["Mr. Foo S01E02", "Bar (UK) S00E22", "Ignored S20E22", "Let's S05E03"]
44
- result = ["Mr. Foo S01E02", "Bar S00E22", "Lets S05E03"]
45
-
46
- dl = DownloadTV::Downloader.new(0, ignored: ["ignored"], path: config_path)
47
- dl.fix_names(shows).must_equal result
48
- end
49
- end
50
-
51
-
52
- describe "the check_date method" do
53
- it "exits the script when up to date" do
54
- begin
55
- dl = DownloadTV::Downloader.new(0, date: Date.today, path: config_path)
56
- run_silently { dl.check_date }
57
- flunk
58
- rescue SystemExit
59
-
60
- end
61
- end
62
-
63
- it "uses the offset to adjust the date" do
64
- # Would exit with offset 0
65
- dl = DownloadTV::Downloader.new(1, date: Date.today, path: config_path)
66
-
67
- date = dl.check_date
68
-
69
- date.must_equal (Date.today-1)
70
- dl.config[:date].must_equal Date.today
71
- end
72
-
73
- end
74
-
75
- describe "the filter_shows method" do
76
- it "removes names with 2160p in them" do
77
- dl = DownloadTV::Downloader.new(0, path: config_path)
78
- links = [["Link 1", ""], ["Link 2 2160p", ""], ["Link 3", ""]]
79
- res = [["Link 1", ""], ["Link 3", ""]]
80
- dl.filter_shows(links).must_equal res
81
- end
82
-
83
- it "removes names with 1080p in them" do
84
- dl = DownloadTV::Downloader.new(0, path: config_path)
85
- links = [["Link.1080p", ""], ["Link 2 2160p", ""], ["Link 3", ""]]
86
- res = [["Link 3", ""]]
87
- dl.filter_shows(links).must_equal res
88
- end
89
-
90
- it "removes names with 720p in them" do
91
- dl = DownloadTV::Downloader.new(0, path: config_path)
92
- links = [["Link 1", ""], ["Link 2 720p", ""], ["Link.720p.rip", ""]]
93
- res = [["Link 1", ""]]
94
- dl.filter_shows(links).must_equal res
95
- end
96
-
97
- it "removes names with WEB in them" do
98
- dl = DownloadTV::Downloader.new(0, path: config_path)
99
- links = [["Link 1 WEBRIP", ""], ["Link 2 rip", ""], ["Link.720p.rip", ""]]
100
- res = [["Link 2 rip", ""]]
101
- dl.filter_shows(links).must_equal res
102
- end
103
-
104
- it "removes names without PROPER or REPACK in them" do
105
- dl = DownloadTV::Downloader.new(0, path: config_path)
106
- links = [["Link 1", ""], ["Link 2 2160p", ""], ["Link 3", ""], ["Link 4 PROPER", ""], ["Link REPACK 5", ""]]
107
- res = [["Link 4 PROPER", ""], ["Link REPACK 5", ""]]
108
- dl.filter_shows(links).must_equal res
109
- end
110
-
111
- it "doesn't apply a filter if it would reject every option" do
112
- dl = DownloadTV::Downloader.new(0, path: config_path)
113
- links = [["Link 1 720p", ""], ["Link 2 2160p", ""], ["Link 720p 3", ""]]
114
- res = [["Link 1 720p", ""], ["Link 720p 3", ""]]
115
- dl.filter_shows(links).must_equal res
116
- end
117
- end
118
-
119
- describe "the get_link method" do
120
- it "returns an empty string when it can't find links" do
121
- t = Minitest::Mock.new
122
- show = "Example Show S01E01"
123
-
124
- t.expect(:get_links, [], [show])
125
- dl = DownloadTV::Downloader.new(0, auto: true, path: config_path)
126
- dl.get_link(t, show).must_equal ""
127
- t.expect(:get_links, [], [show])
128
- dl = DownloadTV::Downloader.new(0, auto: false, path: config_path)
129
- dl.get_link(t, show).must_equal ""
130
-
131
-
132
- end
133
-
134
- it "returns the first link when auto is set to true" do
135
- t = Minitest::Mock.new
136
- show = "Example Show S01E01"
137
-
138
- t.expect(:get_links, [["Name 1", "Link 1"], ["Name 2", "Link 2"]], [show])
139
- dl = DownloadTV::Downloader.new(0, auto: true, path: config_path)
140
- dl.get_link(t, show).must_equal "Link 1"
141
-
142
-
143
- end
144
- end
145
-
146
- describe "the detect_os method" do
147
- it "returns xdg open for linux" do
148
- prev = RbConfig::CONFIG['host_os']
149
- RbConfig::CONFIG['host_os'] = "linux-gnu"
150
-
151
- dl = DownloadTV::Downloader.new(0, path: config_path)
152
- dl.detect_os.must_equal "xdg-open"
153
-
154
- RbConfig::CONFIG['host_os'] = prev
155
- end
156
-
157
- it "returns open for mac" do
158
- prev = RbConfig::CONFIG['host_os']
159
- RbConfig::CONFIG['host_os'] = "darwin15.6.0"
160
-
161
- dl = DownloadTV::Downloader.new(0, path: config_path)
162
- dl.detect_os.must_equal "open"
163
-
164
- RbConfig::CONFIG['host_os'] = prev
165
- end
166
-
167
- it "exits when it can't detect the platform" do
168
- prev = RbConfig::CONFIG['host_os']
169
- RbConfig::CONFIG['host_os'] = "dummy"
170
-
171
- dl = DownloadTV::Downloader.new(0, path: config_path)
172
-
173
- begin
174
- run_silently { dl.detect_os.must_equal "xdg-open" }
175
- flunk
176
- rescue SystemExit
177
-
178
- end
179
-
180
- RbConfig::CONFIG['host_os'] = prev
181
- end
182
- end
183
-
184
- end
4
+ config_path = File.realdirpath("#{__dir__}/test_config")
5
+
6
+ before do
7
+ Dir.chdir(__dir__)
8
+ create_dummy_config(config_path) unless File.exist?(config_path)
9
+ end
10
+
11
+ after do
12
+ File.delete(config_path) if File.exist?(config_path)
13
+ end
14
+
15
+ describe 'when creating the object' do
16
+ it 'should store the first argument as @offset' do
17
+ DownloadTV::Downloader.new(3, path: config_path).offset.must_equal 3
18
+ DownloadTV::Downloader.new(-3, path: config_path).offset.must_equal 3
19
+ end
20
+
21
+ it 'should receive an integer for the offset' do
22
+ -> { DownloadTV::Downloader.new('foo') }.must_raise NoMethodError
23
+ end
24
+
25
+ it 'can receive an optional configuration hash' do
26
+ dl = DownloadTV::Downloader.new(0, auto: true, grabber: 'KAT', path: config_path)
27
+ dl.config[:auto].must_equal true
28
+ dl.config[:grabber].must_equal 'KAT'
29
+ end
30
+ end
31
+
32
+ describe 'the fix_names method' do
33
+ it 'should remove apostrophes, colons and parens' do
34
+ shows = ['Mr. Foo S01E02', 'Bar (UK) S00E22', "Let's S05E03", 'Baz: The Story S05E22']
35
+ result = ['Mr. Foo S01E02', 'Bar S00E22', 'Lets S05E03', 'Baz The Story S05E22']
36
+
37
+ dl = DownloadTV::Downloader.new(0, ignored: [], path: config_path)
38
+ dl.fix_names(shows).must_equal result
39
+ end
40
+
41
+ it 'should remove ignored shows' do
42
+ shows = ['Mr. Foo S01E02', 'Bar (UK) S00E22', 'Ignored S20E22', "Let's S05E03"]
43
+ result = ['Mr. Foo S01E02', 'Bar S00E22', 'Lets S05E03']
44
+
45
+ dl = DownloadTV::Downloader.new(0, ignored: ['ignored'], path: config_path)
46
+ dl.fix_names(shows).must_equal result
47
+ end
48
+ end
49
+
50
+ describe 'the check_date method' do
51
+ it 'exits the script when up to date' do
52
+ dl = DownloadTV::Downloader.new(0, date: Date.today, path: config_path)
53
+ to_run = -> { run_silently { dl.check_date } }
54
+ to_run.must_raise SystemExit
55
+ end
56
+
57
+ it 'uses the offset to adjust the date' do
58
+ # Would exit with offset 0
59
+ dl = DownloadTV::Downloader.new(1, date: Date.today, path: config_path)
60
+
61
+ date = dl.check_date
62
+
63
+ date.must_equal(Date.today - 1)
64
+ dl.config[:date].must_equal Date.today
65
+ end
66
+ end
67
+
68
+ describe 'the filter_shows method' do
69
+ it 'removes names with 2160p in them' do
70
+ dl = DownloadTV::Downloader.new(0, path: config_path)
71
+ links = [['Link 1', ''], ['Link 2 2160p', ''], ['Link 3', '']]
72
+ res = [['Link 1', ''], ['Link 3', '']]
73
+ dl.filter_shows(links).must_equal res
74
+ end
75
+
76
+ it 'removes names with 1080p in them' do
77
+ dl = DownloadTV::Downloader.new(0, path: config_path)
78
+ links = [['Link.1080p', ''], ['Link 2 2160p', ''], ['Link 3', '']]
79
+ res = [['Link 3', '']]
80
+ dl.filter_shows(links).must_equal res
81
+ end
82
+
83
+ it 'removes names with 720p in them' do
84
+ dl = DownloadTV::Downloader.new(0, path: config_path)
85
+ links = [['Link 1', ''], ['Link 2 720p', ''], ['Link.720p.rip', '']]
86
+ res = [['Link 1', '']]
87
+ dl.filter_shows(links).must_equal res
88
+ end
89
+
90
+ it 'removes names with WEB in them' do
91
+ dl = DownloadTV::Downloader.new(0, path: config_path)
92
+ links = [['Link 1 WEBRIP', ''], ['Link 2 rip', ''], ['Link.720p.rip', '']]
93
+ res = [['Link 2 rip', '']]
94
+ dl.filter_shows(links).must_equal res
95
+ end
96
+
97
+ it 'removes names without PROPER or REPACK in them' do
98
+ dl = DownloadTV::Downloader.new(0, path: config_path)
99
+ links = [['Link 1', ''], ['Link 2 2160p', ''], ['Link 3', ''], ['Link 4 PROPER', ''], ['Link REPACK 5', '']]
100
+ res = [['Link 4 PROPER', ''], ['Link REPACK 5', '']]
101
+ dl.filter_shows(links).must_equal res
102
+ end
103
+
104
+ it "doesn't apply a filter if it would reject every option" do
105
+ dl = DownloadTV::Downloader.new(0, path: config_path)
106
+ links = [['Link 1 720p', ''], ['Link 2 2160p', ''], ['Link 720p 3', '']]
107
+ res = [['Link 1 720p', ''], ['Link 720p 3', '']]
108
+ dl.filter_shows(links).must_equal res
109
+ end
110
+ end
111
+
112
+ describe 'the get_link method' do
113
+ it "returns an empty string when it can't find links" do
114
+ t = Minitest::Mock.new
115
+ show = 'Example Show S01E01'
116
+
117
+ t.expect(:get_links, [], [show])
118
+ dl = DownloadTV::Downloader.new(0, auto: true, path: config_path)
119
+ dl.get_link(t, show).must_equal ''
120
+ t.expect(:get_links, [], [show])
121
+ dl = DownloadTV::Downloader.new(0, auto: false, path: config_path)
122
+ dl.get_link(t, show).must_equal ''
123
+ end
124
+
125
+ it 'returns the first link when auto is set to true' do
126
+ t = Minitest::Mock.new
127
+ show = 'Example Show S01E01'
128
+
129
+ t.expect(:get_links, [['Name 1', 'Link 1'], ['Name 2', 'Link 2']], [show])
130
+ dl = DownloadTV::Downloader.new(0, auto: true, path: config_path)
131
+ dl.get_link(t, show).must_equal 'Link 1'
132
+ end
133
+ end
134
+
135
+ describe 'the detect_os method' do
136
+ it 'returns xdg open for linux' do
137
+ prev = RbConfig::CONFIG['host_os']
138
+ RbConfig::CONFIG['host_os'] = 'linux-gnu'
139
+
140
+ dl = DownloadTV::Downloader.new(0, path: config_path)
141
+ dl.detect_os.must_equal 'xdg-open'
142
+
143
+ RbConfig::CONFIG['host_os'] = prev
144
+ end
145
+
146
+ it 'returns open for mac' do
147
+ prev = RbConfig::CONFIG['host_os']
148
+ RbConfig::CONFIG['host_os'] = 'darwin15.6.0'
149
+
150
+ dl = DownloadTV::Downloader.new(0, path: config_path)
151
+ dl.detect_os.must_equal 'open'
152
+
153
+ RbConfig::CONFIG['host_os'] = prev
154
+ end
155
+
156
+ it "exits when it can't detect the platform" do
157
+ prev = RbConfig::CONFIG['host_os']
158
+ RbConfig::CONFIG['host_os'] = 'dummy'
159
+
160
+ dl = DownloadTV::Downloader.new(0, path: config_path)
161
+
162
+ to_run = -> { run_silently { dl.detect_os.must_equal 'xdg-open' } }
163
+ to_run.must_raise SystemExit
164
+
165
+ RbConfig::CONFIG['host_os'] = prev
166
+ end
167
+ end
168
+ end
@@ -1,46 +1,40 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  describe DownloadTV::LinkGrabber do
4
-
5
- grabbers = DownloadTV::Torrent.new.grabbers
6
- instances = grabbers.map { |g| (DownloadTV.const_get g).new }
7
-
8
- instances.each do |grabber|
9
- describe grabber do
10
- it "will have a url attribute on creation" do
11
- grabber.url.wont_be_nil
12
- end
13
-
14
- it "should get a 200 code response" do
15
- grabber.test_connection.code.must_equal "200"
16
- end
17
-
18
- it "will raise NoTorrentsError when torrent can't be found" do
19
- notfound = ->{ grabber.get_links("Totally Fake Show askjdgsaudas") }
20
- notfound.must_raise DownloadTV::NoTorrentsError
21
- end
22
-
23
- it "will return an array with names and links of results when a torrent can be found" do
24
- result = grabber.get_links("Game Of Thrones S04E01")
25
- result.must_be_instance_of Array
26
- result.wont_be :empty?
27
- result.each do |r|
28
- r.size.must_equal 2
29
- r[0].must_be_instance_of String
30
- r[0].upcase.must_include "THRONES"
31
- r[1].must_be_instance_of String
32
- r[1].must_include "magnet:"
33
- end
34
-
35
- end
36
-
37
- end
38
- end
39
-
40
- it "raises an error if the instance doesn't implement get_links" do
41
- ->{ DownloadTV::LinkGrabber.new("").get_links("test") }.must_raise NotImplementedError
42
-
43
- end
44
-
45
-
46
- end
4
+ grabbers = DownloadTV::Torrent.new.grabbers
5
+ instances = grabbers.map { |g| (DownloadTV.const_get g).new }
6
+
7
+ instances.each do |grabber|
8
+ describe grabber do
9
+ it 'will have a url attribute on creation' do
10
+ grabber.url.wont_be_nil
11
+ end
12
+
13
+ it 'should get a 200 code response' do
14
+ grabber.test_connection.code.must_equal '200'
15
+ end
16
+
17
+ it "will raise NoTorrentsError when torrent can't be found" do
18
+ notfound = -> { grabber.get_links('Totally Fake Show askjdgsaudas') }
19
+ notfound.must_raise DownloadTV::NoTorrentsError
20
+ end
21
+
22
+ it 'will return an array with names and links of results when a torrent can be found' do
23
+ result = grabber.get_links('Game Of Thrones S04E01')
24
+ result.must_be_instance_of Array
25
+ result.wont_be :empty?
26
+ result.each do |r|
27
+ r.size.must_equal 2
28
+ r[0].must_be_instance_of String
29
+ r[0].upcase.must_include 'THRONES'
30
+ r[1].must_be_instance_of String
31
+ r[1].must_include 'magnet:'
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ it "raises an error if the instance doesn't implement get_links" do
38
+ -> { DownloadTV::LinkGrabber.new('').get_links('test') }.must_raise NotImplementedError
39
+ end
40
+ end
data/test/test_helper.rb CHANGED
@@ -1,20 +1,20 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
- require "download_tv"
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'download_tv'
3
+ require 'minitest/autorun'
3
4
 
4
- require "minitest/autorun"
5
-
6
-
7
- def create_dummy_config(in_path, config={})
8
- config[:version] = DownloadTV::VERSION if !config[:version]
9
- File.open(in_path, "wb") { |f| Marshal.dump(config, f) }
5
+ def create_dummy_config(in_path, config = {})
6
+ config[:version] = DownloadTV::VERSION unless config[:version]
7
+ File.open(in_path, 'wb') { |f| Marshal.dump(config, f) }
10
8
  end
11
9
 
12
10
  def run_silently
13
- previous_stdout, $stdout = $stdout, StringIO.new
14
- previous_stderr, $stderr = $stderr, StringIO.new
15
- yield
16
- $stdout.string
11
+ previous_stdout = $stdout
12
+ $stdout = StringIO.new
13
+ previous_stderr = $stderr
14
+ $stderr = StringIO.new
15
+ yield
16
+ $stdout.string
17
17
  ensure
18
- $stdout = previous_stdout
19
- $stderr = previous_stderr
20
- end
18
+ $stdout = previous_stdout
19
+ $stderr = previous_stderr
20
+ end