rbrainz 0.1.1 → 0.2.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.
- 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
@@ -0,0 +1,75 @@
|
|
1
|
+
# $Id: test_default_factory.rb 134 2007-07-16 08:46:55Z 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/model'
|
10
|
+
include MusicBrainz
|
11
|
+
|
12
|
+
# Unit test for the Alias model.
|
13
|
+
class TestDefaultFactory < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def setup
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_new_artist
|
22
|
+
factory = Model::DefaultFactory.new
|
23
|
+
assert factory.new_artist.is_a?(Model::Artist)
|
24
|
+
assert factory.new_entity(:artist).is_a?(Model::Artist)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_new_label
|
28
|
+
factory = Model::DefaultFactory.new
|
29
|
+
assert factory.new_label.is_a?(Model::Label)
|
30
|
+
assert factory.new_entity(:label).is_a?(Model::Label)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_new_release
|
34
|
+
factory = Model::DefaultFactory.new
|
35
|
+
assert factory.new_release.is_a?(Model::Release)
|
36
|
+
assert factory.new_entity(:release).is_a?(Model::Release)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_new_track
|
40
|
+
factory = Model::DefaultFactory.new
|
41
|
+
assert factory.new_track.is_a?(Model::Track)
|
42
|
+
assert factory.new_entity(:track).is_a?(Model::Track)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_new_alias
|
46
|
+
factory = Model::DefaultFactory.new
|
47
|
+
assert factory.new_alias.is_a?(Model::Alias)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_new_disc
|
51
|
+
factory = Model::DefaultFactory.new
|
52
|
+
assert factory.new_disc.is_a?(Model::Disc)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_new_relation
|
56
|
+
factory = Model::DefaultFactory.new
|
57
|
+
assert factory.new_relation.is_a?(Model::Relation)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_new_release_event
|
61
|
+
factory = Model::DefaultFactory.new
|
62
|
+
assert factory.new_release_event.is_a?(Model::ReleaseEvent)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_new_tag
|
66
|
+
factory = Model::DefaultFactory.new
|
67
|
+
assert factory.new_tag.is_a?(Model::Tag)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_new_user
|
71
|
+
factory = Model::DefaultFactory.new
|
72
|
+
assert factory.new_user.is_a?(Model::User)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/test/test_disc.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_disc.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_disc.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/unit'
|
7
9
|
require 'rbrainz/model'
|
@@ -19,6 +21,8 @@ class TestDisc < Test::Unit::TestCase
|
|
19
21
|
def test_new_disc
|
20
22
|
disc = nil
|
21
23
|
assert_nothing_raised {disc = Model::Disc.new}
|
24
|
+
assert_nothing_raised {disc = Model::Disc.new('Tit3F0Do_sZ_7NbfM_1vlEbF0wo-')}
|
25
|
+
assert_equal 'Tit3F0Do_sZ_7NbfM_1vlEbF0wo-', disc.id
|
22
26
|
end
|
23
27
|
|
24
28
|
def test_id
|
@@ -26,6 +30,7 @@ class TestDisc < Test::Unit::TestCase
|
|
26
30
|
assert disc.id.nil?
|
27
31
|
assert_nothing_raised {disc.id = 'Tit3F0Do_sZ_7NbfM_1vlEbF0wo-'}
|
28
32
|
assert_equal 'Tit3F0Do_sZ_7NbfM_1vlEbF0wo-', disc.id
|
33
|
+
assert_equal 'Tit3F0Do_sZ_7NbfM_1vlEbF0wo-', disc.to_s
|
29
34
|
end
|
30
35
|
|
31
36
|
def test_sectors
|
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_incomplete_date.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_incomplete_date.rb 97 2007-07-06 13:52:29Z nigel_graham $
|
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'
|
@@ -31,11 +33,12 @@ class TestIncompleteDate < Test::Unit::TestCase
|
|
31
33
|
assert_equal 1969, date.year
|
32
34
|
assert_equal 1, date.month
|
33
35
|
assert_equal 5, date.day
|
34
|
-
assert_nothing_raised {date = Model::IncompleteDate.new(nil)}
|
35
|
-
assert_equal nil, date.year
|
36
|
+
# assert_nothing_raised {date = Model::IncompleteDate.new(nil)}
|
37
|
+
# assert_equal nil, date.year
|
36
38
|
end
|
37
39
|
|
38
40
|
def test_invalid_format
|
41
|
+
assert_raise(ArgumentError) {date = Model::IncompleteDate.new(nil)}
|
39
42
|
assert_raise(ArgumentError) {date = Model::IncompleteDate.new('69-01-05')}
|
40
43
|
assert_raise(ArgumentError) {date = Model::IncompleteDate.new(69)}
|
41
44
|
assert_raise(ArgumentError) {date = Model::IncompleteDate.new('1969/01/05')}
|
@@ -48,13 +51,17 @@ class TestIncompleteDate < Test::Unit::TestCase
|
|
48
51
|
assert_equal '1980', @date_year.to_s
|
49
52
|
end
|
50
53
|
|
51
|
-
def
|
52
|
-
assert_equal(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
assert_equal(
|
57
|
-
|
54
|
+
def test_range
|
55
|
+
assert_equal Date.civil(1980,8,22), @date_year_month_day.begin
|
56
|
+
assert_equal Date.civil(1980,8,23), @date_year_month_day.end
|
57
|
+
assert @date_year_month_day.exclude_end?
|
58
|
+
|
59
|
+
assert_equal Date.civil(1980, 8, 1), @date_year_month.begin
|
60
|
+
assert_equal Date.civil(1980, 9, 1), @date_year_month.end
|
61
|
+
assert @date_year_month.exclude_end?
|
62
|
+
|
63
|
+
assert_equal Date.civil(1980, 1, 1), @date_year.begin
|
64
|
+
assert_equal Date.civil(1981, 1, 1), @date_year.end
|
65
|
+
assert @date_year.exclude_end?
|
58
66
|
end
|
59
|
-
|
60
67
|
end
|
data/test/test_label.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_label.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_label.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
|
|
@@ -12,6 +14,7 @@ class TestLabel < Test::Unit::TestCase
|
|
12
14
|
@tested_class = Model::Label
|
13
15
|
@invalid_entity_types = [:artist, :release, :track]
|
14
16
|
@releases = [Model::Release.new, Model::Release.new]
|
17
|
+
@aliases = [Model::Alias.new, Model::Alias.new]
|
15
18
|
end
|
16
19
|
|
17
20
|
def teardown
|
@@ -24,6 +27,18 @@ class TestLabel < Test::Unit::TestCase
|
|
24
27
|
label = nil
|
25
28
|
assert_nothing_raised {label = Model::Label.new}
|
26
29
|
assert label.is_a?(Model::Entity)
|
30
|
+
|
31
|
+
mbid = Model::MBID.new('9d30e408-1559-448b-b491-2f8de1583ccf', label.entity_type)
|
32
|
+
assert_nothing_raised {label = Model::Label.new(
|
33
|
+
mbid,
|
34
|
+
Model::Label::TYPE_ORIGINAL_PRODUCTION,
|
35
|
+
'Century Media',
|
36
|
+
'Century Media'
|
37
|
+
)}
|
38
|
+
assert_equal mbid, label.id
|
39
|
+
assert_equal Model::Label::TYPE_ORIGINAL_PRODUCTION, label.type
|
40
|
+
assert_equal 'Century Media', label.name
|
41
|
+
assert_equal 'Century Media', label.sort_name
|
27
42
|
end
|
28
43
|
|
29
44
|
def test_name
|
@@ -47,6 +62,14 @@ class TestLabel < Test::Unit::TestCase
|
|
47
62
|
assert_equal 'Disambiguation comment', label.disambiguation
|
48
63
|
end
|
49
64
|
|
65
|
+
def test_unique_name
|
66
|
+
label = Model::Label.new
|
67
|
+
label.name = 'EMI'
|
68
|
+
label.disambiguation = 'Taiwan'
|
69
|
+
assert_equal 'EMI (Taiwan)', label.unique_name
|
70
|
+
assert_equal 'EMI (Taiwan)', label.to_s
|
71
|
+
end
|
72
|
+
|
50
73
|
def test_code
|
51
74
|
label = Model::Label.new
|
52
75
|
assert label.code.nil?
|
@@ -76,32 +99,32 @@ class TestLabel < Test::Unit::TestCase
|
|
76
99
|
assert_equal Model::Label::TYPE_REISSUE_PRODUCTION, label.type
|
77
100
|
end
|
78
101
|
|
79
|
-
def
|
102
|
+
def test_begin_date
|
80
103
|
label = Model::Label.new
|
81
104
|
date = Model::IncompleteDate.new '1988-04-18'
|
82
|
-
assert_nothing_raised {label.
|
83
|
-
assert_equal nil, label.
|
84
|
-
assert_nothing_raised {label.
|
85
|
-
assert_equal date, label.
|
105
|
+
assert_nothing_raised {label.begin_date}
|
106
|
+
assert_equal nil, label.begin_date
|
107
|
+
assert_nothing_raised {label.begin_date = date}
|
108
|
+
assert_equal date, label.begin_date
|
86
109
|
|
87
110
|
# It should be able to supply a date as a string,
|
88
111
|
# but Label should convert it to an IncompleteDate.
|
89
|
-
assert_nothing_raised {label.
|
90
|
-
assert_equal Model::IncompleteDate.new('1988-04-20'), label.
|
112
|
+
assert_nothing_raised {label.begin_date = '1988-04-20'}
|
113
|
+
assert_equal Model::IncompleteDate.new('1988-04-20'), label.begin_date
|
91
114
|
end
|
92
115
|
|
93
|
-
def
|
116
|
+
def test_end_date
|
94
117
|
label = Model::Label.new
|
95
118
|
date = Model::IncompleteDate.new '1988-04-18'
|
96
|
-
assert_nothing_raised {label.
|
97
|
-
assert_equal nil, label.
|
98
|
-
assert_nothing_raised {label.
|
99
|
-
assert_equal date, label.
|
119
|
+
assert_nothing_raised {label.end_date}
|
120
|
+
assert_equal nil, label.end_date
|
121
|
+
assert_nothing_raised {label.end_date = date}
|
122
|
+
assert_equal date, label.end_date
|
100
123
|
|
101
124
|
# It should be able to supply a date as a string,
|
102
125
|
# but Label should convert it to an IncompleteDate.
|
103
|
-
assert_nothing_raised {label.
|
104
|
-
assert_equal Model::IncompleteDate.new('1988-04-20'), label.
|
126
|
+
assert_nothing_raised {label.end_date = '1988-04-20'}
|
127
|
+
assert_equal Model::IncompleteDate.new('1988-04-20'), label.end_date
|
105
128
|
end
|
106
129
|
|
107
130
|
# Many releases can be added
|
@@ -119,4 +142,19 @@ class TestLabel < Test::Unit::TestCase
|
|
119
142
|
assert_equal 0, label.releases.size
|
120
143
|
end
|
121
144
|
|
145
|
+
# Many aliases can be added
|
146
|
+
def test_add_and_remove_aliases
|
147
|
+
label = Model::Label.new
|
148
|
+
assert_equal 0, label.aliases.size
|
149
|
+
assert_nothing_raised {label.aliases << @aliases[0]}
|
150
|
+
assert_equal 1, label.aliases.size
|
151
|
+
assert_nothing_raised {label.aliases << @aliases[1]}
|
152
|
+
assert_equal 2, label.aliases.size
|
153
|
+
|
154
|
+
assert_nothing_raised {label.aliases.delete @aliases[1]}
|
155
|
+
assert_equal 1, label.aliases.size
|
156
|
+
assert_nothing_raised {label.aliases.delete @aliases[0]}
|
157
|
+
assert_equal 0, label.aliases.size
|
158
|
+
end
|
159
|
+
|
122
160
|
end
|
data/test/test_label_filter.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_label_filter.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_label_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'
|
@@ -12,7 +14,8 @@ include MusicBrainz
|
|
12
14
|
class TestLabelFilter < Test::Unit::TestCase
|
13
15
|
|
14
16
|
def setup
|
15
|
-
@filter_hash = {:name => 'Century Media', :limit => 10
|
17
|
+
@filter_hash = {:name => 'Century Media', :limit => 10, :offset => 20,
|
18
|
+
:query => 'alias:Century Media OR alias:Century'}
|
16
19
|
end
|
17
20
|
|
18
21
|
def teardown
|
@@ -26,6 +29,8 @@ class TestLabelFilter < Test::Unit::TestCase
|
|
26
29
|
result_hash = query_string_to_hash filter_string
|
27
30
|
assert_equal @filter_hash[:name], result_hash['name'], filter_string
|
28
31
|
assert_equal @filter_hash[:limit].to_s, result_hash['limit'], filter_string
|
32
|
+
assert_equal @filter_hash[:offset].to_s, result_hash['offset'], filter_string
|
33
|
+
assert_equal @filter_hash[:query].to_s, result_hash['query'], filter_string
|
29
34
|
end
|
30
35
|
|
31
36
|
def test_empty_filter
|
data/test/test_label_includes.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_label_includes.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_label_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'
|
@@ -23,7 +25,8 @@ class TestLabelIncludes < Test::Unit::TestCase
|
|
23
25
|
:release_rels => true,
|
24
26
|
:track_rels => true,
|
25
27
|
:label_rels => true,
|
26
|
-
:url_rels => true
|
28
|
+
:url_rels => true,
|
29
|
+
:tags => true
|
27
30
|
)
|
28
31
|
result_string = includes.to_s
|
29
32
|
assert_equal 'inc=', result_string[0..3]
|
@@ -35,6 +38,7 @@ class TestLabelIncludes < Test::Unit::TestCase
|
|
35
38
|
assert result_array.include?('track-rels')
|
36
39
|
assert result_array.include?('label-rels')
|
37
40
|
assert result_array.include?('url-rels')
|
41
|
+
assert result_array.include?('tags')
|
38
42
|
end
|
39
43
|
|
40
44
|
def test_empty_includes
|
@@ -44,7 +48,8 @@ class TestLabelIncludes < Test::Unit::TestCase
|
|
44
48
|
:release_rels => false,
|
45
49
|
:track_rels => false,
|
46
50
|
:label_rels => false,
|
47
|
-
:url_rels => false
|
51
|
+
:url_rels => false,
|
52
|
+
:tags => false
|
48
53
|
)
|
49
54
|
assert_equal '', includes.to_s
|
50
55
|
|
data/test/test_mbid.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# $Id: test_mbid.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: test_mbid.rb 142 2007-07-17 15:49:57Z 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'
|
@@ -25,35 +27,48 @@ class TestMBID < Test::Unit::TestCase
|
|
25
27
|
def teardown
|
26
28
|
end
|
27
29
|
|
28
|
-
def
|
29
|
-
|
30
|
+
def test_parse
|
31
|
+
assert_equal 'http://musicbrainz.org/artist/9d30e408-1559-448b-b491-2f8de1583ccf',
|
32
|
+
Model::MBID.parse(
|
33
|
+
'http://musicbrainz.org/artist/9d30e408-1559-448b-b491-2f8de1583ccf',
|
34
|
+
:artist).to_s
|
35
|
+
assert_equal 'http://musicbrainz.org/artist/9d30e408-1559-448b-b491-2f8de1583ccf',
|
36
|
+
Model::MBID.parse(
|
37
|
+
'9d30e408-1559-448b-b491-2f8de1583ccf',
|
38
|
+
:artist ).to_s
|
39
|
+
assert_raise(Model::EntityTypeNotMatchingError) {
|
40
|
+
Model::MBID.parse(
|
41
|
+
'http://musicbrainz.org/artist/9d30e408-1559-448b-b491-2f8de1583ccf',
|
42
|
+
:label )
|
43
|
+
}
|
44
|
+
assert_equal Model::VARIOUS_ARTISTS_ID, Model::MBID.parse('http://musicbrainz.org/artist/89ad4ac3-39f7-470e-963a-56509c546377')
|
30
45
|
end
|
31
46
|
|
32
47
|
def test_from_uri
|
33
48
|
@valid_entities.each{|entity|
|
34
49
|
@valid_uuids.each{|uuid|
|
35
50
|
assert_nothing_raised \
|
36
|
-
{Model::MBID.
|
51
|
+
{Model::MBID.parse 'http://musicbrainz.org/' + entity.to_s + '/' + uuid }
|
37
52
|
}
|
38
53
|
}
|
39
54
|
@invalid_uris.each{|uri|
|
40
|
-
assert_raise(Model::InvalidMBIDError) {Model::MBID.
|
55
|
+
assert_raise(Model::InvalidMBIDError, uri) {Model::MBID.parse uri}
|
41
56
|
}
|
42
57
|
end
|
43
58
|
|
44
59
|
def test_from_uuid
|
45
60
|
@valid_entities.each{|entity|
|
46
61
|
@valid_uuids.each{|uuid|
|
47
|
-
assert_nothing_raised {Model::MBID.
|
62
|
+
assert_nothing_raised {Model::MBID.parse uuid, entity}
|
48
63
|
}
|
49
64
|
}
|
50
65
|
@invalid_entities.each{|entity|
|
51
66
|
assert_raise(Model::UnknownEntityError, 'Invalid entity ' + entity.inspect + '') \
|
52
|
-
{Model::MBID.
|
67
|
+
{Model::MBID.parse @valid_uuids[0], entity}
|
53
68
|
}
|
54
69
|
@invalid_uuids.each{|uuid|
|
55
|
-
assert_raise(Model::
|
56
|
-
{Model::MBID.
|
70
|
+
assert_raise(Model::InvalidMBIDError, uuid.inspect) \
|
71
|
+
{Model::MBID.parse uuid, @valid_entities[0]}
|
57
72
|
}
|
58
73
|
end
|
59
74
|
|
@@ -61,9 +76,9 @@ class TestMBID < Test::Unit::TestCase
|
|
61
76
|
@valid_entities.each{|entity|
|
62
77
|
@valid_uuids.each{|uuid|
|
63
78
|
uri = 'http://musicbrainz.org/' + entity.to_s + '/' + uuid
|
64
|
-
mbid = Model::MBID.
|
79
|
+
mbid = Model::MBID.parse uuid, entity
|
65
80
|
assert_equal uri, mbid.to_s
|
66
|
-
mbid = Model::MBID.
|
81
|
+
mbid = Model::MBID.parse uri
|
67
82
|
assert_equal uri, mbid.to_s
|
68
83
|
}
|
69
84
|
}
|
@@ -72,10 +87,10 @@ class TestMBID < Test::Unit::TestCase
|
|
72
87
|
def test_read_attributes
|
73
88
|
@valid_entities.each{|entity|
|
74
89
|
@valid_uuids.each{|uuid|
|
75
|
-
mbid = Model::MBID.
|
90
|
+
mbid = Model::MBID.parse uuid, entity
|
76
91
|
assert_equal entity.to_sym, mbid.entity
|
77
92
|
assert_equal uuid, mbid.uuid
|
78
|
-
mbid = Model::MBID.
|
93
|
+
mbid = Model::MBID.parse 'http://musicbrainz.org/' + entity.to_s + '/' + uuid
|
79
94
|
assert_equal entity.to_sym, mbid.entity
|
80
95
|
assert_equal uuid, mbid.uuid
|
81
96
|
}
|
@@ -84,14 +99,14 @@ class TestMBID < Test::Unit::TestCase
|
|
84
99
|
|
85
100
|
# Test if the attributes are read only.
|
86
101
|
def test_write_attributes
|
87
|
-
mbid = Model::MBID.
|
102
|
+
mbid = Model::MBID.parse @valid_uuids[0], @valid_entities[0]
|
88
103
|
assert_raise(NoMethodError) {mbid.entity = :release}
|
89
104
|
assert_raise(NoMethodError) {mbid.uuid = @valid_uuids[0]}
|
90
105
|
end
|
91
106
|
|
92
107
|
def test_equality
|
93
|
-
mbid1 = Model::MBID.
|
94
|
-
mbid2 = Model::MBID.
|
108
|
+
mbid1 = Model::MBID.parse @valid_uuids[0], @valid_entities[0]
|
109
|
+
mbid2 = Model::MBID.parse @valid_uuids[0], @valid_entities[0]
|
95
110
|
assert_equal mbid1, mbid1
|
96
111
|
assert_equal mbid1, mbid2
|
97
112
|
end
|