yasuyuki-nicovideo 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoLogin < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_login_OK
9
+ valid_account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
10
+ nv = Nicovideo.new(valid_account['mail'], valid_account['password'])
11
+
12
+ assert_nothing_raised { nv.login }
13
+
14
+ sleep 1
15
+ end
16
+
17
+ def test_login_NG
18
+ invalid_account = {'mail' => 'invalid@account.com', 'password' => 'invalid' }
19
+ nv = Nicovideo.new(invalid_account['mail'], invalid_account['password'])
20
+
21
+ assert_raise(Nicovideo::LoginError) {
22
+ nv.login
23
+ }
24
+
25
+ sleep 1
26
+ end
27
+
28
+ def test_auto_login
29
+ valid_account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
30
+ nv = Nicovideo.new(valid_account['mail'], valid_account['password'])
31
+
32
+ assert_nothing_raised {
33
+ nv.watch('sm500873') {|v|
34
+ puts v.title
35
+ }
36
+ }
37
+ end
38
+ end
@@ -0,0 +1,92 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoMyList < Test::Unit::TestCase
4
+
5
+ def setup
6
+ account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
7
+ @nv = Nicovideo.new(account['mail'], account['password'])
8
+ @nv.login
9
+
10
+ @mid_valid = '3982404' # 公開マイリスト
11
+ @mid_invalid = 'smfdsaf' # IDが間違っている
12
+ @mid_notopened = '3825220' # 非公開
13
+ @mid_testers_own = '12149071' # テスト用アカウントに登録されているマイリストのID
14
+
15
+ @vid_valid = 'sm2407057' # 閲覧可能(短い動画)
16
+ end
17
+
18
+ def test_mylist_valid
19
+ ml = nil
20
+ assert_nothing_raised {
21
+ ml = @nv.mylist(@mid_valid)
22
+ }
23
+ assert_instance_of(Nicovideo::MyList, ml)
24
+ puts ml.id
25
+ puts ml.url
26
+ puts ml.title
27
+ puts ml.description
28
+ puts ml.videos.size
29
+ ml.videos.each {|v|
30
+ puts v.id + ' ' + v.title
31
+ }
32
+ assert_equal(@mid_valid, ml.id)
33
+ assert_equal("http://www.nicovideo.jp/mylist/"+@mid_valid, ml.url)
34
+ assert_instance_of(String, ml.title)
35
+ assert_instance_of(String, ml.description)
36
+ assert_instance_of(Array, ml.videos)
37
+
38
+ ml.title = "test"
39
+ assert_equal("test", ml.title)
40
+
41
+ sleep 5
42
+ end
43
+
44
+ def test_mylist_invalid
45
+ ml = nil
46
+ assert_nothing_raised {
47
+ ml = @nv.mylist(@mid_invalid)
48
+ }
49
+
50
+ assert_equal(@mid_invalid, ml.id)
51
+ assert_equal("http://www.nicovideo.jp/mylist/"+@mid_invalid, ml.url)
52
+
53
+ assert_raise(Nicovideo::NotFound) { ml.title }
54
+ assert_raise(Nicovideo::NotFound) { ml.description }
55
+ assert_raise(Nicovideo::NotFound) { ml.videos }
56
+
57
+ sleep 5
58
+ end
59
+
60
+ def test_mylist_notopened
61
+ ml = nil
62
+ assert_nothing_raised {
63
+ ml = @nv.mylist(@mid_notopened)
64
+ }
65
+
66
+ assert_equal(@mid_notopened, ml.id)
67
+ assert_equal("http://www.nicovideo.jp/mylist/"+@mid_notopened, ml.url)
68
+
69
+ assert_raise(Nicovideo::Forbidden) { ml.title }
70
+ assert_raise(Nicovideo::Forbidden) { ml.description }
71
+ assert_raise(Nicovideo::Forbidden) { ml.videos }
72
+
73
+ sleep 5
74
+ end
75
+
76
+ def test_add
77
+ ml = nil
78
+ assert_nothing_raised {
79
+ ml = @nv.mylist(@mid_testers_own)
80
+ }
81
+
82
+ # FIXME removing video function is NOT implemented,
83
+ # so you MUST remove video from mylist before test.
84
+ assert_nothing_raised {
85
+ ml.add @vid_valid
86
+ }
87
+
88
+ assert_equal(@vid_valid, ml.videos.last.video_id)
89
+
90
+ sleep 5
91
+ end
92
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoNewarrival < Test::Unit::TestCase
4
+
5
+ def setup
6
+ account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
7
+ @nv = Nicovideo.new(account['mail'], account['password'])
8
+ @nv.login
9
+ end
10
+
11
+ def test_ranking_valid
12
+ rv = nil
13
+ assert_nothing_raised {
14
+ rv = @nv.newarrival
15
+ }
16
+
17
+ rv.each {|v|
18
+ # puts v.id + ':' + v.published_at.to_s + ':' + v.title
19
+ puts v.id + ':' + v.title
20
+ # sleep 1
21
+ }
22
+
23
+ sleep 1
24
+ end
25
+
26
+ def test_ranking_invalid
27
+ end
28
+
29
+ def test_ranking_notopened
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideo < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,108 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoOpenList < Test::Unit::TestCase
4
+
5
+ def setup
6
+ account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
7
+ @nv = Nicovideo.new(account['mail'], account['password'])
8
+ @nv.login
9
+
10
+ @vid_valid = 'sm500873' # 公開マイリストが存在(単一ページ)
11
+ @vid_valid2 = 'sm500873' # 公開マイリストが存在(複数ページ)
12
+ @vid_invalid = 'smfdsafd' # IDがおかしい(動画が存在しない)
13
+ @vid_notfound = 'sm500875' # 公開マイリストが存在しない
14
+ end
15
+
16
+ def test_openlist_testing
17
+ result = @nv.openlist("sm500873")
18
+ result.each {|v|
19
+ puts v.title
20
+ }
21
+ end
22
+
23
+ def test_openlist_valid
24
+ ol = nil
25
+ assert_nothing_raised {
26
+ ol = @nv.openlist(@vid_valid)
27
+ }
28
+ assert_instance_of(Nicovideo::OpenList, ol)
29
+ assert_instance_of(Array, ol.mylists)
30
+ assert_instance_of(Array, ol.to_a)
31
+ assert_instance_of(Fixnum, ol.total_size)
32
+ assert_instance_of(Fixnum, ol.pagenum)
33
+ assert(ol.has_next?)
34
+ assert(!ol.has_prev?)
35
+
36
+ assert_nothing_raised {
37
+ ol.pagenum = 2
38
+ }
39
+
40
+ assert_equal(ol.pagenum, 2)
41
+ assert(ol.has_next?)
42
+ assert(ol.has_prev?)
43
+
44
+ assert_nothing_raised {
45
+ ol.next
46
+ }
47
+
48
+ assert_equal(ol.pagenum, 3)
49
+
50
+ sleep 1
51
+ end
52
+
53
+ def test_openlist_valid2
54
+ ol = nil
55
+
56
+ assert_nothing_raised {
57
+ @nv.watch(@vid_valid) {|v|
58
+ ol = v.openlist
59
+ }
60
+ }
61
+
62
+ assert_instance_of(Nicovideo::OpenList, ol)
63
+ assert_instance_of(Array, ol.mylists)
64
+ assert_instance_of(Array, ol.to_a)
65
+ assert_instance_of(Fixnum, ol.total_size)
66
+ assert_instance_of(Fixnum, ol.pagenum)
67
+ assert(ol.has_next?)
68
+ assert(!ol.has_prev?)
69
+
70
+ sleep 1
71
+ end
72
+
73
+ def test_openlist_invalid
74
+ ol = nil
75
+ assert_nothing_raised {
76
+ ol = @nv.openlist(@vid_invalid)
77
+ }
78
+
79
+ assert_instance_of(Nicovideo::OpenList, ol)
80
+ assert_raise(Nicovideo::NotFound) { ol.mylists }
81
+ assert_raise(Nicovideo::NotFound) { ol.to_a }
82
+ assert_raise(Nicovideo::NotFound) { ol.total_size }
83
+ assert_raise(Nicovideo::NotFound) { ol.has_next? }
84
+ assert_raise(Nicovideo::NotFound) { ol.has_prev? }
85
+ assert_raise(Nicovideo::NotFound) { ol.next }
86
+ assert_raise(Nicovideo::NotFound) { ol.prev }
87
+
88
+ sleep 1
89
+ end
90
+
91
+ def test_openlist_notfound
92
+ ol = nil
93
+ assert_nothing_raised {
94
+ ol = @nv.openlist(@vid_notfound)
95
+ }
96
+
97
+ assert_instance_of(Nicovideo::OpenList, ol)
98
+ assert_raise(Nicovideo::NotFound) { ol.mylists }
99
+ assert_raise(Nicovideo::NotFound) { ol.to_a }
100
+ assert_raise(Nicovideo::NotFound) { ol.total_size }
101
+ assert_raise(Nicovideo::NotFound) { ol.has_next? }
102
+ assert_raise(Nicovideo::NotFound) { ol.has_prev? }
103
+ assert_raise(Nicovideo::NotFound) { ol.next }
104
+ assert_raise(Nicovideo::NotFound) { ol.prev }
105
+
106
+ sleep 1
107
+ end
108
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoRandom < Test::Unit::TestCase
4
+
5
+ def setup
6
+ account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
7
+ @nv = Nicovideo.new(account['mail'], account['password'])
8
+ @nv.login
9
+ end
10
+
11
+ def test_ranking_valid
12
+ rv = nil
13
+ assert_nothing_raised {
14
+ rv = @nv.random
15
+ }
16
+
17
+ rv.each {|v|
18
+ # puts v.id + ':' + v.published_at.to_s + ':' + v.title
19
+ puts v.id + ':' + v.title
20
+ # sleep 1
21
+ }
22
+
23
+ sleep 1
24
+ end
25
+
26
+ def test_ranking_invalid
27
+ end
28
+
29
+ def test_ranking_notopened
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoRanking < Test::Unit::TestCase
4
+
5
+ def setup
6
+ account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
7
+ @nv = Nicovideo.new(account['mail'], account['password'])
8
+ @nv.login
9
+ end
10
+
11
+ def test_ranking_valid
12
+ rv = nil
13
+ assert_nothing_raised {
14
+ rv = @nv.ranking
15
+ }
16
+
17
+ rv.each {|v|
18
+ # puts v.id + ':' + v.published_at.to_s + ':' + v.title
19
+ puts v.id + ':' + v.title
20
+ sleep 1
21
+ }
22
+
23
+ sleep 1
24
+ end
25
+
26
+ def test_ranking_invalid
27
+ end
28
+
29
+ def test_ranking_notopened
30
+ end
31
+ end
@@ -0,0 +1,96 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoSearch < Test::Unit::TestCase
4
+
5
+ def setup
6
+ account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
7
+ @nv = Nicovideo.new(account['mail'], account['password'])
8
+ @nv.login
9
+ end
10
+
11
+ def output_results result
12
+ puts result.total_size
13
+ result.each {|v|
14
+ puts v.id + ':' + v.title
15
+ }
16
+ end
17
+ =begin
18
+ def test_search_testing0
19
+ result = @nv.search("aaa")
20
+ output_results result
21
+ sleep 3
22
+ end
23
+
24
+ def test_search_testing1
25
+ result = @nv.search("ミク")
26
+ output_results result
27
+ sleep 3
28
+ end
29
+ =end
30
+
31
+ def test_search_next
32
+ result = @nv.search("ミク", 'n')
33
+ output_results result
34
+ i = 1
35
+ sleep 5
36
+ while result.has_next? && i < 5
37
+ output_results result.next
38
+ i += 1
39
+ sleep 5
40
+ end
41
+
42
+ sleep 3
43
+ end
44
+ def test_search_prev
45
+ result = @nv.search("ミク", 'n', nil, 5)
46
+ output_results result
47
+ i = 5
48
+ sleep 5
49
+ while result.has_prev? && i > 0
50
+ output_results result.prev
51
+ i -= 1
52
+ sleep 5
53
+ end
54
+ end
55
+
56
+ =begin
57
+ def test_search_testing2
58
+ result = @nv.search("ミク", 'n')
59
+ puts result.total_size
60
+ result.each { |v|
61
+ puts v.title
62
+ }
63
+ sleep 3
64
+ end
65
+
66
+ def test_search_testing3
67
+ result = @nv.search("ミク", 'n', 'd')
68
+ puts result.total_size
69
+ result.each {|v|
70
+ puts v.title
71
+ }
72
+ sleep 3
73
+ end
74
+ =end
75
+ =begin
76
+ def test_search_valid
77
+ rv = nil
78
+ assert_nothing_raised {
79
+ rv = @nv.ranking
80
+ }
81
+
82
+ rv.each {|v|
83
+ puts v.id + ':' + v.published_at.to_s + ':' + v.title
84
+ sleep 1
85
+ }
86
+
87
+ sleep 1
88
+ end
89
+
90
+ def test_search_invalid
91
+ end
92
+
93
+ def test_search_notopened
94
+ end
95
+ =end
96
+ end
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoTagSearch < Test::Unit::TestCase
4
+
5
+ def setup
6
+ account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
7
+ @nv = Nicovideo.new(account['mail'], account['password'])
8
+ @nv.login
9
+ end
10
+
11
+ def test_tagsearch_testing0
12
+ result = @nv.tagsearch("aaa")
13
+ puts result.total_size
14
+ result.each {|v|
15
+ puts v.title
16
+ }
17
+ sleep 1
18
+ end
19
+
20
+ def test_tagsearch_testing1
21
+ result = @nv.tagsearch("ミク")
22
+ result.each {|v|
23
+ puts v.title
24
+ }
25
+ sleep 1
26
+ end
27
+
28
+ def test_tagsearch_testing1
29
+ result = @nv.tagsearch("ミク", 'v', 'a')
30
+ result.each {|v|
31
+ puts v.title
32
+ }
33
+ sleep 1
34
+ end
35
+
36
+ def test_search_testing2
37
+ result = @nv.tagsearch("ミク", 'n')
38
+ result.each {|v|
39
+ puts v.title
40
+ }
41
+ end
42
+
43
+
44
+ =begin
45
+ def test_search_valid
46
+ rv = nil
47
+ assert_nothing_raised {
48
+ rv = @nv.ranking
49
+ }
50
+
51
+ rv.each {|v|
52
+ puts v.id + ':' + v.published_at.to_s + ':' + v.title
53
+ sleep 1
54
+ }
55
+
56
+ sleep 1
57
+ end
58
+
59
+ def test_search_invalid
60
+ end
61
+
62
+ def test_search_notopened
63
+ end
64
+ =end
65
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'kagemusha'
3
+ require 'open-uri'
4
+
5
+ class Test_Thumbnail < Test::Unit::TestCase
6
+ def setup
7
+ @client = Nicovideo::Thumbnail.new
8
+ end
9
+
10
+ def test_get
11
+ thumbnail = @client.get("sm2424611")
12
+ assert("sm2424611", thumbnail["video_id"])
13
+ end
14
+
15
+ def test_get_nonexistent_video
16
+ assert_raise(::Errno::ENOENT) {
17
+ @client.get "sm1"
18
+ }
19
+ end
20
+
21
+ def test_get_timeout
22
+ Kagemusha.new(Kernel) do |m|
23
+ m.def(:open) { sleep 30 }
24
+ m.swap {
25
+ assert_raise(TimeoutError) {
26
+ @client.get("sm2424611")
27
+ }
28
+ }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,108 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNicovideoVideoPage < Test::Unit::TestCase
4
+
5
+ def setup
6
+ account = YAML.load_file(ENV['HOME'] + '/.nicovideo/account.yml')
7
+ @nv = Nicovideo.new(account['mail'], account['password'])
8
+ @nv.login
9
+
10
+ # @vid_valid = 'sm500873' # 閲覧可能(組曲)
11
+ @vid_valid = 'sm2407057' # 閲覧可能(短い動画)
12
+ @vid_invalid = 'smfdsafd' # IDが間違っている
13
+ @vid_notfound = 'sm500875' # 削除済み
14
+ end
15
+
16
+ # TODO: add test cases of openlist and mylist
17
+ def test_watch_ikinari
18
+ vp = nil
19
+ assert_nothing_raised {
20
+ vp = @nv.watch(@vid_valid)
21
+ }
22
+ assert_nothing_raised { vp.flv }
23
+ sleep 5
24
+ end
25
+
26
+ def test_type
27
+ vp = @nv.watch(@vid_valid) {|vp|
28
+ assert_instance_of(String, vp.type)
29
+ puts vp.type
30
+ }
31
+ end
32
+
33
+ def test_watch_valid
34
+ vp = nil
35
+ assert_nothing_raised {
36
+ vp = @nv.watch(@vid_valid)
37
+ }
38
+ assert_instance_of(Nicovideo::VideoPage, vp)
39
+ assert_instance_of(Array, vp.tags)
40
+ assert_instance_of(String, vp.title)
41
+ assert_instance_of(Time, vp.published_at)
42
+ assert_instance_of(Nicovideo::Comments, vp.comments)
43
+ assert_instance_of(String, vp.csrf_token)
44
+
45
+ puts vp.tags
46
+ puts vp.title
47
+ puts vp.published_at
48
+ puts vp.csrf_token
49
+ # assert_nothing_raised { vp.flv }
50
+ #assert_instance_of(String, vp.flv)
51
+ #assert_instance_of(String, vp.video)
52
+ # File.open("#{@vid_valid}.flv", "wb") {|f| f.write vp.flv }
53
+
54
+ sleep 1
55
+ end
56
+
57
+ def test_watch_valid2
58
+ vp = nil
59
+ assert_nothing_raised {
60
+ @nv.watch(@vid_valid) {|v|
61
+ assert_instance_of(Nicovideo::VideoPage, v)
62
+ assert_instance_of(Array, v.tags)
63
+ assert_instance_of(String, v.title)
64
+ assert_instance_of(Nicovideo::Comments, v.comments)
65
+ assert_instance_of(String, v.csrf_token)
66
+ # assert_instance_of(String, v.flv)
67
+ # assert_instance_of(String, v.video)
68
+ }
69
+ }
70
+
71
+ sleep 1
72
+ end
73
+
74
+ # watchは、VideoPageインスタンスを返すのみなので例外発生なし
75
+ # VideoPageインスタンスのメソッドを実行したときに例外発生
76
+ def test_watch_invalid
77
+ vp = nil
78
+ assert_nothing_raised {
79
+ vp = @nv.watch(@vid_invalid)
80
+ }
81
+ assert_instance_of(Nicovideo::VideoPage, vp)
82
+ assert_raise(Nicovideo::NotFound) { vp.tags }
83
+ assert_raise(Nicovideo::NotFound) { vp.title }
84
+ assert_raise(Nicovideo::NotFound) { vp.comments }
85
+ assert_raise(Nicovideo::NotFound) { vp.flv }
86
+ assert_raise(Nicovideo::NotFound) { vp.video }
87
+ assert_raise(Nicovideo::NotFound) { vp.csrf_token }
88
+
89
+ sleep 1
90
+ end
91
+
92
+ # watchは、VideoPageインスタンスを返すのみなので例外発生なし
93
+ def test_watch_notfound
94
+ vp = nil
95
+ assert_nothing_raised {
96
+ vp = @nv.watch(@vid_notfound)
97
+ }
98
+ assert_instance_of(Nicovideo::VideoPage, vp)
99
+ assert_raise(Nicovideo::NotFound) { vp.tags }
100
+ assert_raise(Nicovideo::NotFound) { vp.title }
101
+ assert_raise(Nicovideo::NotFound) { vp.comments }
102
+ assert_raise(Nicovideo::NotFound) { vp.flv }
103
+ assert_raise(Nicovideo::NotFound) { vp.video }
104
+ assert_raise(Nicovideo::NotFound) { vp.csrf_token }
105
+
106
+ sleep 1
107
+ end
108
+ end