rbrainz 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +31 -0
- data/LICENSE +1 -1
- data/README +3 -2
- data/Rakefile +40 -22
- data/TODO +6 -23
- data/doc/README.rdoc +50 -21
- data/examples/getartist.rb +6 -4
- data/examples/getuser.rb +30 -0
- data/examples/searchartists.rb +35 -0
- data/lib/rbrainz.rb +12 -7
- data/lib/rbrainz/core_ext.rb +8 -0
- data/lib/rbrainz/core_ext/mbid.rb +30 -0
- data/lib/rbrainz/core_ext/net_http_digest.rb +52 -0
- data/lib/rbrainz/core_ext/range.rb +28 -0
- data/lib/rbrainz/core_ext/range/equality.rb +232 -0
- data/lib/rbrainz/data/countrynames.rb +7 -5
- data/lib/rbrainz/data/languagenames.rb +8 -5
- data/lib/rbrainz/data/releasetypenames.rb +34 -0
- data/lib/rbrainz/data/scriptnames.rb +8 -5
- data/lib/rbrainz/model.rb +27 -35
- data/lib/rbrainz/model/alias.rb +31 -7
- data/lib/rbrainz/model/artist.rb +30 -41
- data/lib/rbrainz/model/collection.rb +102 -0
- data/lib/rbrainz/model/default_factory.rb +78 -0
- data/lib/rbrainz/model/disc.rb +45 -8
- data/lib/rbrainz/model/entity.rb +122 -53
- data/lib/rbrainz/model/incomplete_date.rb +31 -47
- data/lib/rbrainz/model/individual.rb +103 -0
- data/lib/rbrainz/model/label.rb +42 -33
- data/lib/rbrainz/model/mbid.rb +111 -40
- data/lib/rbrainz/model/relation.rb +78 -14
- data/lib/rbrainz/model/release.rb +119 -31
- data/lib/rbrainz/model/release_event.rb +38 -9
- data/lib/rbrainz/model/scored_collection.rb +99 -0
- data/lib/rbrainz/model/tag.rb +39 -0
- data/lib/rbrainz/model/track.rb +37 -13
- data/lib/rbrainz/model/user.rb +48 -0
- data/lib/rbrainz/utils.rb +9 -0
- data/lib/rbrainz/utils/data.rb +78 -0
- data/lib/rbrainz/utils/helper.rb +22 -0
- data/lib/rbrainz/version.rb +15 -0
- data/lib/rbrainz/webservice.rb +32 -6
- data/lib/rbrainz/webservice/filter.rb +124 -47
- data/lib/rbrainz/webservice/includes.rb +49 -10
- data/lib/rbrainz/webservice/mbxml.rb +228 -173
- data/lib/rbrainz/webservice/query.rb +312 -25
- data/lib/rbrainz/webservice/webservice.rb +164 -27
- data/test/lib/mock_webservice.rb +53 -0
- data/test/lib/test_entity.rb +27 -8
- data/test/lib/test_factory.rb +47 -0
- data/test/lib/testing_helper.rb +7 -5
- data/test/test-data/invalid/artist/tags_1.xml +6 -0
- data/test/test-data/valid/artist/Tchaikovsky-2.xml +12 -0
- data/test/test-data/valid/label/Atlantic_Records_2.xml +3 -0
- data/test/test-data/valid/label/Atlantic_Records_3.xml +11 -0
- data/test/test-data/valid/release/Highway_61_Revisited_2.xml +12 -0
- data/test/test-data/valid/track/Silent_All_These_Years_6.xml +8 -0
- data/test/test_alias.rb +13 -7
- data/test/test_artist.rb +26 -4
- data/test/test_artist_filter.rb +11 -6
- data/test/test_artist_includes.rb +11 -6
- data/test/test_collection.rb +66 -0
- data/test/test_default_factory.rb +75 -0
- data/test/test_disc.rb +9 -4
- data/test/test_incomplete_date.rb +21 -14
- data/test/test_label.rb +56 -18
- data/test/test_label_filter.rb +10 -5
- data/test/test_label_includes.rb +11 -6
- data/test/test_mbid.rb +34 -19
- data/test/test_mbxml.rb +242 -72
- data/test/test_query.rb +92 -7
- data/test/test_range_equality.rb +144 -0
- data/test/test_relation.rb +18 -7
- data/test/test_release.rb +15 -4
- data/test/test_release_event.rb +16 -4
- data/test/test_release_filter.rb +11 -5
- data/test/test_release_includes.rb +11 -6
- data/test/test_scored_collection.rb +86 -0
- data/test/test_tag.rb +39 -0
- data/test/test_track.rb +15 -4
- data/test/test_track_filter.rb +11 -5
- data/test/test_track_includes.rb +11 -6
- data/test/test_utils.rb +41 -0
- data/test/test_webservice.rb +16 -17
- metadata +93 -57
data/test/test_query.rb
CHANGED
@@ -1,24 +1,109 @@
|
|
1
|
-
# $Id: test_query.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_query.rb 147 2007-07-19 17:10:26Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
5
7
|
|
6
8
|
require 'test/unit'
|
7
9
|
require 'rbrainz'
|
10
|
+
require 'mock_webservice'
|
11
|
+
require 'test_factory'
|
8
12
|
include MusicBrainz
|
9
13
|
|
10
14
|
# Unit test for the Query class.
|
11
15
|
class TestQuery < Test::Unit::TestCase
|
12
16
|
|
13
17
|
def setup
|
18
|
+
@webservice = MockWebservice.new
|
19
|
+
@query = Webservice::Query.new(@webservice)
|
14
20
|
end
|
15
21
|
|
16
22
|
def teardown
|
17
23
|
end
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
25
|
+
def test_get_artist
|
26
|
+
id = 'c0b2500e-0cef-4130-869d-732b23ed9df5'
|
27
|
+
entity = @query.get_artist_by_id(id)
|
28
|
+
assert entity.is_a?(Model::Artist)
|
29
|
+
assert_equal id, entity.id.uuid
|
30
|
+
assert_equal 'Tori Amos', entity.name
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_get_artists
|
34
|
+
filter = Webservice::ArtistFilter.new(:name=>'Tori Amos')
|
35
|
+
collection = @query.get_artists(filter)
|
36
|
+
assert collection.is_a?(Model::Collection)
|
37
|
+
assert_equal 3, collection.size
|
38
|
+
collection.entities.each {|e| assert e.is_a?(Model::Artist) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_get_release
|
42
|
+
id = '290e10c5-7efc-4f60-ba2c-0dfc0208fbf5'
|
43
|
+
entity = @query.get_release_by_id(id)
|
44
|
+
assert entity.is_a?(Model::Release)
|
45
|
+
assert_equal id, entity.id.uuid
|
46
|
+
assert_equal 'Under the Pink', entity.title
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_get_releases
|
50
|
+
filter = Webservice::ReleaseFilter.new(:title=>'Under the Pink')
|
51
|
+
collection = @query.get_releases(filter)
|
52
|
+
assert collection.is_a?(Model::Collection)
|
53
|
+
assert_equal 2, collection.size
|
54
|
+
collection.entities.each {|e| assert e.is_a?(Model::Release) }
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_get_track
|
58
|
+
id = 'd6118046-407d-4e06-a1ba-49c399a4c42f'
|
59
|
+
entity = @query.get_track_by_id(id)
|
60
|
+
assert entity.is_a?(Model::Track)
|
61
|
+
assert_equal id, entity.id.uuid
|
62
|
+
assert_equal 'Silent All These Years', entity.title
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_get_tracks
|
66
|
+
filter = Webservice::TrackFilter.new(:title=>'Little Earthquakes')
|
67
|
+
collection = @query.get_tracks(filter)
|
68
|
+
assert collection.is_a?(Model::Collection)
|
69
|
+
assert_equal 3, collection.size
|
70
|
+
collection.entities.each {|e| assert e.is_a?(Model::Track) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_get_label
|
74
|
+
id = '50c384a2-0b44-401b-b893-8181173339c7'
|
75
|
+
entity = @query.get_label_by_id(id)
|
76
|
+
assert entity.is_a?(Model::Label)
|
77
|
+
assert_equal id, entity.id.uuid
|
78
|
+
assert_equal 'Atlantic Records', entity.name
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_get_labels
|
82
|
+
filter = Webservice::LabelFilter.new(:name=>'Atlantic Records')
|
83
|
+
collection = @query.get_labels(filter)
|
84
|
+
assert collection.is_a?(Model::Collection)
|
85
|
+
assert_equal 2, collection.size
|
86
|
+
collection.entities.each {|e| assert e.is_a?(Model::Label) }
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_get_user_by_name
|
90
|
+
user = @query.get_user_by_name('matt')
|
91
|
+
assert user.is_a?(Model::User)
|
92
|
+
assert_equal false, user.show_nag?
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_factory
|
96
|
+
factory = MyFactory.new
|
97
|
+
query = Webservice::Query.new(@webservice, :factory=>factory)
|
98
|
+
|
99
|
+
id = '290e10c5-7efc-4f60-ba2c-0dfc0208fbf5'
|
100
|
+
entity = query.get_release_by_id(id)
|
101
|
+
assert entity.is_a?(MyRelease)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_response_error
|
105
|
+
assert_raise(Webservice::ResponseError){@query.get_artist_by_id('00000000-0000-0000-0000-000000000000')}
|
106
|
+
assert_raise(Webservice::ResponseError){@query.get_artist_by_id('11111111-1111-1111-1111-111111111111')}
|
22
107
|
end
|
23
108
|
|
24
109
|
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# $Id: test_range_equality.rb 111 2007-07-10 14:09:52Z nigel_graham $
|
2
|
+
#
|
3
|
+
# Author:: Nigel Graham (mailto:nigel_graham@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
require 'rbrainz'
|
10
|
+
|
11
|
+
# Unit test for range equality extension.
|
12
|
+
class TestRangeEquality < Test::Unit::TestCase
|
13
|
+
TESTSET =
|
14
|
+
[
|
15
|
+
[ 1..11, 13..30, :before?], # a before b
|
16
|
+
[ 1...12, 13...30, :before?], # a before b
|
17
|
+
[ 1..11, 13, :before?], # a before b
|
18
|
+
[ 13..30, 1..11, :after?], # a after b
|
19
|
+
[13...30, 1...12, :after?], # a after b
|
20
|
+
[ 13..30, 11, :after?], # a after b
|
21
|
+
[ 1..12, 1...13, :eql?], # a equals b
|
22
|
+
[ 1..12, 1..12, :eql?], # a equals b
|
23
|
+
[ 1...13, 1..12, :eql?], # a equals b
|
24
|
+
[ 1...13, 1...13, :eql?], # a equals b
|
25
|
+
[ 1...2, 1, :eql?], # a equals b
|
26
|
+
[ 1..1, 1, :eql?], # a equals b
|
27
|
+
[ 1...13, 13..30, :meets_beginning_of?], # a meets_beginning_of b
|
28
|
+
[ 1..12, 13..30, :meets_beginning_of?], # a meets_beginning_of b
|
29
|
+
[ 1...13, 13, :meets_beginning_of?], # a meets_beginning_of b
|
30
|
+
[ 1..12, 13, :meets_beginning_of?], # a meets_beginning_of b
|
31
|
+
[ 13..30, 1...13, :meets_end_of?], # a meets_end_of b
|
32
|
+
[ 13..30, 1..12, :meets_end_of?], # a meets_end_of b
|
33
|
+
[ 13..30, 12, :meets_end_of?], # a meets_end_of b
|
34
|
+
[ 1..13, 13..30, :overlaps_beginning_of?], # a overlaps_beginning_of b
|
35
|
+
[ 1...14, 13..30, :overlaps_beginning_of?], # a overlaps_beginning_of b
|
36
|
+
[ 1..29, 13..30, :overlaps_beginning_of?], # a overlaps_beginning_of b
|
37
|
+
[ 1...30, 13..30, :overlaps_beginning_of?], # a overlaps_beginning_of b
|
38
|
+
[ 13..30, 1..13, :overlaps_end_of?], # a overlaps_end_of b
|
39
|
+
[ 13..30, 1...14, :overlaps_end_of?], # a overlaps_end_of b
|
40
|
+
[ 13..30, 1..29, :overlaps_end_of?], # a overlaps_end_of b
|
41
|
+
[ 13..30, 1...30, :overlaps_end_of?], # a overlaps_end_of b
|
42
|
+
[ 13..30, 12..31, :during?], # a during b
|
43
|
+
[13...30, 12..30, :during?], # a during b
|
44
|
+
[13...30, 12...31, :during?], # a during b
|
45
|
+
[ 13..30, 12...32, :during?], # a during b
|
46
|
+
[ 12..31, 13..30, :contains?], # a contains b
|
47
|
+
[ 12..30, 13...30, :contains?], # a contains b
|
48
|
+
[12...31, 13...30, :contains?], # a contains b
|
49
|
+
[12...32, 13..30, :contains?], # a contains b
|
50
|
+
[12...32, 13, :contains?], # a contains b
|
51
|
+
[ 13..30, 13..31, :starts?], # a starts b
|
52
|
+
[13...30, 13..30, :starts?], # a starts b
|
53
|
+
[ 13..30, 13...32, :starts?], # a starts b
|
54
|
+
[13...30, 13...31, :starts?], # a starts b
|
55
|
+
[ 13..31, 13..30, :started_by?], # a started_by b
|
56
|
+
[ 13..30, 13...30, :started_by?], # a started_by b
|
57
|
+
[13...32, 13..30, :started_by?], # a started_by b
|
58
|
+
[13...31, 13...30, :started_by?], # a started_by b
|
59
|
+
[13...31, 13, :started_by?], # a started_by b
|
60
|
+
[ 14..30, 13..30, :finishes?], # a finishes b
|
61
|
+
[14...30, 13..29, :finishes?], # a finishes b
|
62
|
+
[ 14..30, 13...31, :finishes?], # a finishes b
|
63
|
+
[14...30, 13...30, :finishes?], # a finishes b
|
64
|
+
[ 13..30, 14..30, :finished_by?], # a finished_by b
|
65
|
+
[ 13..29, 14...30, :finished_by?], # a finished_by b
|
66
|
+
[13...31, 14..30, :finished_by?], # a finished_by b
|
67
|
+
[13...30, 14...30, :finished_by?], # a finished_by b
|
68
|
+
[13...30, 29, :finished_by?], # a finished_by b
|
69
|
+
]
|
70
|
+
OPERATIONS = [
|
71
|
+
:before?,
|
72
|
+
:after?,
|
73
|
+
:eql?,
|
74
|
+
:meets_beginning_of?,
|
75
|
+
:meets_end_of?,
|
76
|
+
:overlaps_beginning_of?,
|
77
|
+
:overlaps_end_of?,
|
78
|
+
:during?,
|
79
|
+
:contains?,
|
80
|
+
:starts?,
|
81
|
+
:started_by?,
|
82
|
+
:finishes?,
|
83
|
+
:finished_by?,
|
84
|
+
]
|
85
|
+
|
86
|
+
def self.make_test_method(s)
|
87
|
+
st = s.to_s.chop
|
88
|
+
class_eval %Q{
|
89
|
+
def test_#{st}
|
90
|
+
TESTSET.each do |a,b,op|
|
91
|
+
if op == #{s.inspect}
|
92
|
+
assert a.send(#{s.inspect}, b), a.inspect + ".#{s.to_s} " + b.inspect
|
93
|
+
else
|
94
|
+
assert !a.send(#{s.inspect},b), '!' + a.inspect + ".#{s.to_s} " + b.inspect
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
}, __FILE__
|
99
|
+
end
|
100
|
+
|
101
|
+
OPERATIONS.each do |op|
|
102
|
+
make_test_method(op)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_lteq
|
106
|
+
TESTSET.each do |a,b,op|
|
107
|
+
if op == :before? || op == :meets_beginning_of?
|
108
|
+
assert a <= b, a.inspect + " <= " + b.inspect
|
109
|
+
else
|
110
|
+
assert !(a <= b), '!(' + a.inspect + " <= " + b.inspect + ')'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_gteq
|
116
|
+
TESTSET.each do |a,b,op|
|
117
|
+
if op == :after? || op == :meets_end_of?
|
118
|
+
assert a >= b, a.inspect + " >= " + b.inspect
|
119
|
+
else
|
120
|
+
assert !(a >= b), '!(' + a.inspect + " >= " + b.inspect + ')'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_between
|
126
|
+
TESTSET.each do |a,b,op|
|
127
|
+
if op == :starts? || op == :during? || op == :finishes?
|
128
|
+
assert a.between?(b), a.inspect + ".between? " + b.inspect
|
129
|
+
else
|
130
|
+
assert !a.between?(b), '!' + a.inspect + ".between? " + b.inspect + ''
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_include
|
136
|
+
TESTSET.each do |a,b,op|
|
137
|
+
if op == :started_by? || op == :contains? || op == :eql? || op == :finished_by?
|
138
|
+
assert a.include?(b), a.inspect + ".include? " + b.inspect
|
139
|
+
else
|
140
|
+
assert !a.include?(b), '!' + a.inspect + ".include? " + b.inspect + ''
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/test/test_relation.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_relation.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_relation.rb 120 2007-07-12 08:28:11Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
5
7
|
|
6
8
|
require 'test/unit'
|
7
9
|
require 'rbrainz/model'
|
@@ -12,15 +14,24 @@ class TestRelation < Test::Unit::TestCase
|
|
12
14
|
|
13
15
|
def setup
|
14
16
|
@target_entity = Model::Artist.new
|
15
|
-
@target_entity.id = Model::MBID.
|
17
|
+
@target_entity.id = Model::MBID.parse '727ad90b-7ef4-48d2-8f16-c34016544822', :artist
|
16
18
|
end
|
17
19
|
|
18
20
|
def teardown
|
19
21
|
end
|
20
22
|
|
21
23
|
def test_new_relation
|
22
|
-
|
23
|
-
assert_nothing_raised {
|
24
|
+
relation = nil
|
25
|
+
assert_nothing_raised {relation = Model::Relation.new}
|
26
|
+
|
27
|
+
assert_nothing_raised {relation = Model::Relation.new(
|
28
|
+
'Wikipedia',
|
29
|
+
'http://www.example.com',
|
30
|
+
Model::Relation::DIR_FORWARD
|
31
|
+
)}
|
32
|
+
assert_equal 'Wikipedia', relation.type
|
33
|
+
assert_equal 'http://www.example.com', relation.target
|
34
|
+
assert_equal Model::Relation::DIR_FORWARD, relation.direction
|
24
35
|
end
|
25
36
|
|
26
37
|
def test_type
|
data/test/test_release.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_release.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_release.rb 138 2007-07-17 09:05:01Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
5
7
|
|
6
8
|
require 'test_entity'
|
7
9
|
|
@@ -26,6 +28,14 @@ class TestRelease < Test::Unit::TestCase
|
|
26
28
|
release = nil
|
27
29
|
assert_nothing_raised {release = Model::Release.new}
|
28
30
|
assert release.is_a?(Model::Entity)
|
31
|
+
|
32
|
+
mbid = Model::MBID.new('9d30e408-1559-448b-b491-2f8de1583ccf', release.entity_type)
|
33
|
+
assert_nothing_raised {release = Model::Release.new(
|
34
|
+
mbid,
|
35
|
+
'Draconian Times'
|
36
|
+
)}
|
37
|
+
assert_equal mbid, release.id
|
38
|
+
assert_equal 'Draconian Times', release.title
|
29
39
|
end
|
30
40
|
|
31
41
|
def test_title
|
@@ -33,6 +43,7 @@ class TestRelease < Test::Unit::TestCase
|
|
33
43
|
assert release.title.nil?
|
34
44
|
assert_nothing_raised {release.title = 'Draconian Times'}
|
35
45
|
assert_equal 'Draconian Times', release.title
|
46
|
+
assert_equal 'Draconian Times', release.to_s
|
36
47
|
end
|
37
48
|
|
38
49
|
def test_asin
|
data/test/test_release_event.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_release_event.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_release_event.rb 120 2007-07-12 08:28:11Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
5
7
|
|
6
8
|
require 'test/unit'
|
7
9
|
require 'rbrainz/model'
|
@@ -16,6 +18,16 @@ class TestReleaseEvent < Test::Unit::TestCase
|
|
16
18
|
def teardown
|
17
19
|
end
|
18
20
|
|
21
|
+
def test_new
|
22
|
+
event = nil
|
23
|
+
assert_nothing_raised {event = Model::ReleaseEvent.new(
|
24
|
+
'SE',
|
25
|
+
'2007-04-18'
|
26
|
+
)}
|
27
|
+
assert_equal 'SE', event.country
|
28
|
+
assert_equal Model::IncompleteDate.new('2007-04-18'), event.date
|
29
|
+
end
|
30
|
+
|
19
31
|
def test_date
|
20
32
|
event = Model::ReleaseEvent.new
|
21
33
|
date = Model::IncompleteDate.new '2007-04-18'
|
data/test/test_release_filter.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_release_filter.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_release_filter.rb 121 2007-07-12 08:56:19Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
5
7
|
|
6
8
|
require 'test/unit'
|
7
9
|
require 'testing_helper'
|
@@ -23,7 +25,9 @@ class TestReleaseFilter < Test::Unit::TestCase
|
|
23
25
|
:asin => 'B00004VVW9',
|
24
26
|
:lang => 'ENG',
|
25
27
|
:script => 'Latn',
|
26
|
-
:limit => 10
|
28
|
+
:limit => 10,
|
29
|
+
:offset => 20,
|
30
|
+
:query => 'date:2000'
|
27
31
|
}
|
28
32
|
end
|
29
33
|
|
@@ -47,6 +51,8 @@ class TestReleaseFilter < Test::Unit::TestCase
|
|
47
51
|
assert_equal @filter_hash[:lang], result_hash['lang'], filter_string
|
48
52
|
assert_equal @filter_hash[:script], result_hash['script'], filter_string
|
49
53
|
assert_equal @filter_hash[:limit].to_s, result_hash['limit'], filter_string
|
54
|
+
assert_equal @filter_hash[:offset].to_s, result_hash['offset'], filter_string
|
55
|
+
assert_equal @filter_hash[:query].to_s, result_hash['query'], filter_string
|
50
56
|
end
|
51
57
|
|
52
58
|
def test_empty_filter
|
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_release_includes.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_release_includes.rb 118 2007-07-11 22:46:58Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
5
7
|
|
6
8
|
require 'test/unit'
|
7
9
|
require 'rbrainz'
|
@@ -29,7 +31,8 @@ class TestReleaseIncludes < Test::Unit::TestCase
|
|
29
31
|
:track_rels => true,
|
30
32
|
:label_rels => true,
|
31
33
|
:url_rels => true,
|
32
|
-
:track_level_rels => true
|
34
|
+
:track_level_rels => true,
|
35
|
+
:tags => true
|
33
36
|
)
|
34
37
|
result_string = includes.to_s
|
35
38
|
assert_equal 'inc=', result_string[0..3]
|
@@ -47,6 +50,7 @@ class TestReleaseIncludes < Test::Unit::TestCase
|
|
47
50
|
assert result_array.include?('label-rels')
|
48
51
|
assert result_array.include?('url-rels')
|
49
52
|
assert result_array.include?('track-level-rels')
|
53
|
+
assert result_array.include?('tags')
|
50
54
|
end
|
51
55
|
|
52
56
|
def test_empty_includes
|
@@ -62,7 +66,8 @@ class TestReleaseIncludes < Test::Unit::TestCase
|
|
62
66
|
:track_rels => false,
|
63
67
|
:label_rels => false,
|
64
68
|
:url_rels => false,
|
65
|
-
:track_level_rels => false
|
69
|
+
:track_level_rels => false,
|
70
|
+
:tags => false
|
66
71
|
)
|
67
72
|
assert_equal '', includes.to_s
|
68
73
|
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# $Id: test_collection.rb 114 2007-07-10 19:33:22Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
require 'rbrainz'
|
10
|
+
include MusicBrainz
|
11
|
+
|
12
|
+
# Unit test for the Collection class.
|
13
|
+
class TestScoredCollection < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@artist_one = Model::Artist.new
|
17
|
+
@artist_two = Model::Artist.new
|
18
|
+
@artist_three = Model::Artist.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_scored_collection
|
25
|
+
collection = Model::ScoredCollection.new(102, 8)
|
26
|
+
assert_equal 102, collection.count
|
27
|
+
assert_equal 8, collection.offset
|
28
|
+
|
29
|
+
collection.count = 99
|
30
|
+
collection.offset=15
|
31
|
+
assert_equal 99, collection.count
|
32
|
+
assert_equal 15, collection.offset
|
33
|
+
|
34
|
+
assert collection.empty?
|
35
|
+
|
36
|
+
# Fill the collection
|
37
|
+
assert_nothing_raised {
|
38
|
+
collection << Model::ScoredCollection::Entry.new(@artist_one, 100)
|
39
|
+
collection << [@artist_two, 98]
|
40
|
+
# The score can be ignored
|
41
|
+
collection << @artist_three
|
42
|
+
}
|
43
|
+
assert_equal 3, collection.size
|
44
|
+
assert !collection.empty?
|
45
|
+
|
46
|
+
# Iterate over the collection
|
47
|
+
n = 0
|
48
|
+
collection.each {|entry|
|
49
|
+
assert entry.entity.is_a?(Model::Artist), entry.entity.inspect
|
50
|
+
assert((entry.score.is_a?(Integer) or entry.score.nil?), entry.score.inspect)
|
51
|
+
n += 1
|
52
|
+
}
|
53
|
+
assert_equal collection.size, n
|
54
|
+
|
55
|
+
# Iterate over the artists only, ignoring the scores
|
56
|
+
n = 0
|
57
|
+
collection.entities.each {|artist|
|
58
|
+
assert artist.is_a?(Model::Artist), artist.inspect
|
59
|
+
n += 1
|
60
|
+
}
|
61
|
+
assert_equal collection.size, n
|
62
|
+
|
63
|
+
# Random access
|
64
|
+
assert_equal @artist_one, collection[0].entity
|
65
|
+
assert_equal 100, collection[0].score
|
66
|
+
assert_equal @artist_two, collection[1].entity
|
67
|
+
assert_equal 98, collection[1].score
|
68
|
+
assert_equal @artist_three, collection[2].entity
|
69
|
+
assert_equal nil, collection[2].score
|
70
|
+
|
71
|
+
# Convert collection to array
|
72
|
+
array = collection.to_a
|
73
|
+
assert_equal @artist_one, array[0].entity
|
74
|
+
assert_equal 100, array[0].score
|
75
|
+
assert_equal @artist_two, array[1].entity
|
76
|
+
assert_equal 98, array[1].score
|
77
|
+
assert_equal @artist_three, array[2].entity
|
78
|
+
assert_equal nil, array[2].score
|
79
|
+
|
80
|
+
# Access the entities as an array
|
81
|
+
assert_equal @artist_one, collection.entities[0]
|
82
|
+
assert_equal @artist_two, collection.entities[1]
|
83
|
+
assert_equal @artist_three, collection.entities[2]
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|