vk_music 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ require "minitest/autorun"
2
+ require_relative "../lib/vk_music.rb"
3
+
4
+ begin
5
+ CLIENT = VkMusic::Client.new(username: ARGV[0], password: ARGV[1])
6
+ rescue VkMusic::LoginError
7
+ puts "Unable to login! Please check provided credetionals"
8
+ exit
9
+ end
10
+
11
+ class TestVkMusic < MiniTest::Test
12
+
13
+ # NOTICE: This method is indirectly tested in test_post.rb
14
+
15
+ def test_simple
16
+ re = CLIENT.attached_audios_amount("https://vk.com/wall-184089233_6")
17
+ assert_equal(1, re, "This post got only 1 attached audio")
18
+ end
19
+
20
+ def test_empty
21
+ re = CLIENT.attached_audios_amount("https://vk.com/wall-184089233_2")
22
+ assert_equal(0, re, "This post got no attached audios")
23
+ end
24
+
25
+ def test_single_audio
26
+ re = CLIENT.attached_audios_amount("https://vk.com/wall-184089233_6")
27
+ assert_equal(1, re, "This post got only 1 attached audio")
28
+ end
29
+
30
+ def test_single_audio_with_options
31
+ re = CLIENT.attached_audios_amount(owner_id: -184089233, post_id: 6)
32
+ assert_equal(1, re, "This post got only 1 attached audio")
33
+ end
34
+
35
+ def test_no_audio
36
+ re = CLIENT.attached_audios_amount("https://vk.com/wall-184089233_2")
37
+ assert_equal(0, re, "This post got no attached audios")
38
+ end
39
+
40
+ def test_url_to_reply
41
+ re = CLIENT.attached_audios_amount("https://m.vk.com/wall-4790861_10108")
42
+ assert_equal(1, re, "Although this link redirects to comment, audios from post must be parsed")
43
+ end
44
+
45
+ def test_playlist
46
+ re = CLIENT.attached_audios_amount("vk.com/wall-184089233_4")
47
+ assert_equal(0, re, "This post got no attached audios")
48
+ end
49
+
50
+ def test_comments_with_audios
51
+ re = CLIENT.attached_audios_amount("https://m.vk.com/wall-39786657_189247")
52
+ assert_equal(1, re, "This post got 1 attached audio")
53
+ end
54
+
55
+ def test_repost_with_no_audios
56
+ re = CLIENT.attached_audios_amount("https://vk.com/wall-184936953_1")
57
+ assert_equal(0, re, "This post got no attached audios")
58
+ end
59
+
60
+ def test_repost_with_audios
61
+ re = CLIENT.attached_audios_amount("https://vk.com/wall-184936953_2")
62
+ assert_equal(1, re, "This post got 1 attached audio")
63
+ end
64
+
65
+ def test_repost_with_playlist
66
+ re = CLIENT.attached_audios_amount("https://vk.com/wall-184936953_3")
67
+ assert_equal(0, re, "This post got no attached audios")
68
+ end
69
+
70
+ def test_bad_url
71
+ assert_raises(ArgumentError) do
72
+ CLIENT.attached_audios_amount("ae")
73
+ end
74
+ end
75
+
76
+ def test_nonexistent_post
77
+ assert_raises(VkMusic::ParseError) do
78
+ CLIENT.attached_audios_amount("https://m.vk.com/wall-4790861_1052600000")
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,92 @@
1
+ require "minitest/autorun"
2
+ require_relative "../lib/vk_music.rb"
3
+
4
+ begin
5
+ CLIENT = VkMusic::Client.new(username: ARGV[0], password: ARGV[1])
6
+ rescue VkMusic::LoginError
7
+ puts "Unable to login! Please check provided credetionals"
8
+ exit
9
+ end
10
+
11
+ class TestVkMusic < MiniTest::Test
12
+
13
+ def test_user
14
+ pl = CLIENT.audios(owner_id: 8024985)
15
+ assert_instance_of(VkMusic::Playlist, pl, "User audios must be returned as a playlist (cause it is actually is playlist)")
16
+ refute_empty(pl, "There must be some music")
17
+ assert_instance_of(VkMusic::Audio, pl[0], "Results must be of class Audio")
18
+ refute_empty(pl[0].url, "Audio must have download url")
19
+ end
20
+
21
+ def test_user_without_url
22
+ pl = CLIENT.audios("vk.com/id8024985", with_url: false)
23
+ assert_instance_of(VkMusic::Playlist, pl, "User audios must be returned as a playlist (cause it is actually is playlist)")
24
+ refute_empty(pl, "There must be some music")
25
+ assert_instance_of(VkMusic::Audio, pl[0], "Results must be of class Audio")
26
+ assert(pl[0].url_accessable?, "Audio must have all the data needed for getting download URL")
27
+ end
28
+
29
+ def test_user_by_audios_url
30
+ pl = CLIENT.audios("https://m.vk.com/audios8024985")
31
+ refute_empty(pl, "This user got audios")
32
+ end
33
+
34
+ def test_incorrect_id
35
+ assert_raises(VkMusic::ParseError) do
36
+ CLIENT.audios(owner_id: 42424242424242424242424242)
37
+ end
38
+ end
39
+
40
+ def test_user_with_locked_audios
41
+ assert_raises(VkMusic::ParseError) do
42
+ CLIENT.audios(owner_id: 152719703)
43
+ end
44
+ end
45
+
46
+ def test_user_with_empty_audios
47
+ pl = CLIENT.audios(owner_id: 437727675)
48
+ assert_empty(pl, "This user got no audios")
49
+ end
50
+
51
+ def test_group
52
+ pl = CLIENT.audios(owner_id: -4790861)
53
+ refute_empty(pl, "There must be some music")
54
+ refute_nil(pl[0].url, "Audio must have download url")
55
+ end
56
+
57
+ def test_group_with_upper_limit_1
58
+ pl = CLIENT.audios(owner_id: -72589944, up_to: 10)
59
+ assert_equal(10, pl.length, "Size of result must match given limit") # This group got more audios
60
+ refute_nil(pl[0].url, "Audio must have download url")
61
+ end
62
+
63
+ def test_group_with_upper_limit_2
64
+ pl = CLIENT.audios(owner_id: -72589944, up_to: 111, with_url: true)
65
+ assert_equal(111, pl.size, "Size of result must match given limit")
66
+ refute_nil(pl[0].url, "Audio must have download url")
67
+ #refute_nil(pl[-1].url, "Audio must have download url") # Won't have link cause of VK restrictions
68
+ end
69
+
70
+ def test_group_with_upper_limit_3
71
+ pl = CLIENT.audios(owner_id: -39786657, up_to: 1000, with_url: false)
72
+ assert_equal(1000, pl.size, "Size of result must match given limit") # NOTICE: VK restrictions
73
+ assert(pl[0].url_accessable?, "Audio must have all the data needed for getting download URL")
74
+ assert(pl[-1].url_accessable?, "Audio must have all the data needed for getting download URL")
75
+ end
76
+
77
+ def test_group_with_no_audios
78
+ pl = CLIENT.audios("vk.com/club52298374")
79
+ assert_empty(pl, "This group got no audios")
80
+ end
81
+
82
+ def test_group_by_custom_id
83
+ pl = CLIENT.audios("vk.com/mashup")
84
+ refute_empty(pl, "This group got audios")
85
+ end
86
+
87
+ def test_group_by_audios_url
88
+ pl = CLIENT.audios("https://m.vk.com/audios-39786657")
89
+ refute_empty(pl, "This group got audios")
90
+ end
91
+
92
+ end
data/test/test_find.rb ADDED
@@ -0,0 +1,43 @@
1
+ require "minitest/autorun"
2
+ require_relative "../lib/vk_music.rb"
3
+
4
+ begin
5
+ CLIENT = VkMusic::Client.new(username: ARGV[0], password: ARGV[1])
6
+ rescue VkMusic::LoginError
7
+ puts "Unable to login! Please check provided credetionals"
8
+ exit
9
+ end
10
+
11
+ class TestVkMusic < MiniTest::Test
12
+
13
+ def test_find
14
+ results = CLIENT.find("Rick Astley")
15
+ refute_empty(results, "There must be some music of Rick Astley")
16
+ assert_instance_of(VkMusic::Audio, results[0], "Results of search must be of class Audio")
17
+ refute_nil(results[0].url, "Audio must have download url")
18
+ end
19
+
20
+ def test_find_no_query
21
+ results = CLIENT.find("")
22
+ assert_empty(results, "There must be no results for empty query")
23
+ end
24
+
25
+ def test_find_no_results
26
+ results = CLIENT.find("I'm pretty sure no one ever would name a song like this 282E8EE")
27
+ assert_empty(results, "There must be no results for such query")
28
+ end
29
+
30
+ def test_search_with_hash
31
+ results = CLIENT.search(query: "Sexualizer")
32
+ refute_empty(results, "There must be some good music")
33
+ assert_instance_of(VkMusic::Audio, results[0], "Results of search must be of class Audio")
34
+ refute_nil(results[0].url, "Audio must have download url")
35
+ end
36
+
37
+ def test_find_bad_arg
38
+ assert_raises(ArgumentError) do
39
+ CLIENT.search("Good music", query: "or not")
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,61 @@
1
+ require "minitest/autorun"
2
+ require_relative "../lib/vk_music.rb"
3
+
4
+ begin
5
+ CLIENT = VkMusic::Client.new(username: ARGV[0], password: ARGV[1])
6
+ rescue VkMusic::LoginError
7
+ puts "Unable to login! Please check provided credetionals"
8
+ exit
9
+ end
10
+
11
+ class TestVkMusic < MiniTest::Test
12
+
13
+ def test_one_id
14
+ results = CLIENT.from_id([
15
+ "2000202604_456242434_32f6f3df29dc8e9c71_82fbafed15ef65709b"
16
+ ])
17
+ refute_empty(results, "There must be some music")
18
+ assert_instance_of(Array, results, "Result must be an Array")
19
+ assert_instance_of(VkMusic::Audio, results[0], "Results of search must be of class Audio")
20
+ refute_nil(results[0].url, "Audio must have download url")
21
+ end
22
+
23
+ def test_two_id
24
+ results = CLIENT.from_id([
25
+ "2000202604_456242434_32f6f3df29dc8e9c71_82fbafed15ef65709b",
26
+ ["2000023175", "456242595", "addd832f78d7c61b6d", "b6b14f49280d4d55f0"]
27
+ ])
28
+ assert_equal(2, results.size, "There must be 2 audios")
29
+ refute_nil(results[1].url, "Audio must have download url")
30
+ end
31
+
32
+ # TODO: test with many audios
33
+
34
+ def test_bad_last
35
+ assert_raises(VkMusic::ParseError) do
36
+ CLIENT.from_id([
37
+ "2000202604_456242434_32f6f3df29dc8e9c71_82fbafed15ef65709b",
38
+ ["42", "1337", "aaaa", "aaaaaa"]
39
+ ])
40
+ end
41
+ end
42
+
43
+ def test_bad_first
44
+ assert_raises(VkMusic::ParseError) do
45
+ CLIENT.from_id([
46
+ ["42", "1337", "aaaa", "aaaaaa"],
47
+ "2000202604_456242434_32f6f3df29dc8e9c71_82fbafed15ef65709b"
48
+ ])
49
+ end
50
+ end
51
+
52
+ def test_bad_all
53
+ assert_raises(VkMusic::ParseError) do
54
+ CLIENT.from_id([
55
+ ["42", "1337", "aaaa", "aaaaaa"],
56
+ "123_123_123_123"
57
+ ])
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,46 @@
1
+ require "minitest/autorun"
2
+ require_relative "../lib/vk_music.rb"
3
+
4
+ begin
5
+ CLIENT = VkMusic::Client.new(username: ARGV[0], password: ARGV[1])
6
+ rescue VkMusic::LoginError
7
+ puts "Unable to login! Please check provided credetionals"
8
+ exit
9
+ end
10
+
11
+ class TestVkMusic < MiniTest::Test
12
+
13
+ def test_empty_group
14
+ re = CLIENT.last_post_id("https://vk.com/club185224844")
15
+ assert_nil(re, "This group is empty")
16
+ end
17
+
18
+ def test_not_empty_group
19
+ re = CLIENT.last_post_id("https://vk.com/mashup")
20
+ refute_nil(re, "This group is not empty")
21
+ end
22
+
23
+ def test_not_empty_user
24
+ re = CLIENT.last_post_id("https://vk.com/id1")
25
+ refute_nil(re, "This user got posts")
26
+ end
27
+
28
+ def test_bad_url_1
29
+ assert_raises(VkMusic::ParseError) do
30
+ CLIENT.last_post_id("https://vk.com/id10000000000000")
31
+ end
32
+ end
33
+
34
+ def test_bad_url_2
35
+ assert_raises(VkMusic::ParseError) do
36
+ CLIENT.last_post_id("https://vk.com/feed")
37
+ end
38
+ end
39
+
40
+ def test_bad_url_3
41
+ assert_raises(ArgumentError) do
42
+ CLIENT.last_post_id("https://vk.com/id0")
43
+ end
44
+ end
45
+
46
+ end
data/test/test_login.rb CHANGED
@@ -22,7 +22,7 @@ class TestVkMusic < MiniTest::Test
22
22
  puts "Unable to login! Please check provided credetionals"
23
23
  end
24
24
  refute_nil(client, "Client not defined")
25
- refute_nil(client.name, "User name undefined")
25
+ refute_empty(client.name, "User name undefined")
26
26
  refute_nil(client.id, "User id undefined")
27
27
  end
28
28
 
@@ -0,0 +1,113 @@
1
+ require "minitest/autorun"
2
+ require_relative "../lib/vk_music.rb"
3
+
4
+ begin
5
+ CLIENT = VkMusic::Client.new(username: ARGV[0], password: ARGV[1])
6
+ rescue VkMusic::LoginError
7
+ puts "Unable to login! Please check provided credetionals"
8
+ exit
9
+ end
10
+
11
+ class TestVkMusic < MiniTest::Test
12
+
13
+ def test_user_link_with_id
14
+ id = CLIENT.page_id("https://vk.com/id51842614")
15
+ assert_equal(51842614, id, "Ids don't match")
16
+ end
17
+
18
+ def test_user_custom_link
19
+ id = CLIENT.page_id("https://vk.com/kopatych56")
20
+ assert_equal(51842614, id, "Ids don't match")
21
+ end
22
+
23
+ def test_user_custom
24
+ id = CLIENT.page_id("kopatych56")
25
+ assert_equal(51842614, id, "Ids don't match")
26
+ end
27
+
28
+ def test_user_id
29
+ id = CLIENT.page_id("51842614")
30
+ assert_equal(51842614, id, "Ids don't match")
31
+ end
32
+
33
+ def test_user_id_with_prefix
34
+ id = CLIENT.page_id("id51842614")
35
+ assert_equal(51842614, id, "Ids don't match")
36
+ end
37
+
38
+ def test_user_audios
39
+ id = CLIENT.page_id("https://vk.com/audios51842614")
40
+ assert_equal(51842614, id, "Ids don't match")
41
+ end
42
+
43
+
44
+ def test_group_link_with_id
45
+ id = CLIENT.page_id("https://vk.com/public39786657")
46
+ assert_equal(-39786657, id, "Ids don't match")
47
+ end
48
+
49
+ def test_group_custom_link
50
+ id = CLIENT.page_id("https://vk.com/mashup")
51
+ assert_equal(-39786657, id, "Ids don't match")
52
+ end
53
+
54
+ def test_group_custom
55
+ id = CLIENT.page_id("mashup")
56
+ assert_equal(-39786657, id, "Ids don't match")
57
+ end
58
+
59
+ def test_group_id
60
+ id = CLIENT.page_id("-39786657")
61
+ assert_equal(-39786657, id, "Ids don't match")
62
+ end
63
+
64
+ def test_group_id_with_prefix
65
+ id = CLIENT.page_id("public39786657")
66
+ assert_equal(-39786657, id, "Ids don't match")
67
+ end
68
+
69
+ def test_group_audios
70
+ id = CLIENT.page_id("https://vk.com/audios-39786657")
71
+ assert_equal(-39786657, id, "Ids don't match")
72
+ end
73
+
74
+
75
+ def test_user_deleted
76
+ id = CLIENT.page_id("https://vk.com/id245722576")
77
+ assert_equal(245722576, id, "Ids don't match")
78
+ end
79
+
80
+ def test_user_no_photos
81
+ id = CLIENT.page_id("drop_the_treble")
82
+ assert_equal(437727675, id, "Ids don't match")
83
+ end
84
+
85
+ def test_user_private
86
+ id = CLIENT.page_id("poppingeyesocketcherry") # I hope this guy won't change his custom
87
+ assert_equal(300415, id, "Ids don't match")
88
+ end
89
+
90
+ def test_group_no_photos
91
+ id = CLIENT.page_id("vk.com/opentestroom")
92
+ assert_equal(-184089233, id, "Ids don't match")
93
+ end
94
+
95
+ def test_bad_url
96
+ assert_raises(VkMusic::ParseError) do
97
+ CLIENT.page_id("https://vk.com/feed")
98
+ end
99
+ end
100
+
101
+ def test_bad_custom
102
+ assert_raises(VkMusic::ParseError) do
103
+ CLIENT.page_id("a")
104
+ end
105
+ end
106
+
107
+ def test_empty
108
+ assert_raises(VkMusic::ParseError) do
109
+ CLIENT.page_id("")
110
+ end
111
+ end
112
+
113
+ end