| 1 |
use strict; |
| 2 |
use Test::More; |
| 3 |
use Data::Dumper; |
| 4 |
|
| 5 |
use WebService::MusicBrainz; |
| 6 |
|
| 7 |
sub exit_if_mb_busy { |
| 8 |
my $res = shift; |
| 9 |
if(exists $res->{error} && $res->{error} =~ m/^The MusicBrainz web server is currently busy/) { |
| 10 |
done_testing(); |
| 11 |
exit(0); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
my $ws = WebService::MusicBrainz->new(); |
| 16 |
ok($ws); |
| 17 |
|
| 18 |
# JSON TESTS |
| 19 |
my $s1_res = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e' }); |
| 20 |
exit_if_mb_busy($s1_res); |
| 21 |
|
| 22 |
ok($s1_res->{type} eq 'Person'); |
| 23 |
ok($s1_res->{'sort-name'} eq 'Prince'); |
| 24 |
ok($s1_res->{name} eq 'Prince'); |
| 25 |
ok($s1_res->{country} eq 'US'); |
| 26 |
ok($s1_res->{gender} eq 'Male'); |
| 27 |
sleep(1); |
| 28 |
|
| 29 |
my $s2_res = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e', inc => 'releases' }); |
| 30 |
exit_if_mb_busy($s2_res); |
| 31 |
|
| 32 |
ok($s2_res->{type} eq 'Person'); |
| 33 |
ok(exists $s2_res->{releases}); |
| 34 |
ok($s2_res->{name} eq 'Prince'); |
| 35 |
sleep(1); |
| 36 |
|
| 37 |
my $s3_res = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e', inc => ['releases','aliases'] }); |
| 38 |
exit_if_mb_busy($s3_res); |
| 39 |
ok(exists $s3_res->{releases}); |
| 40 |
ok(exists $s3_res->{aliases}); |
| 41 |
sleep(1); |
| 42 |
|
| 43 |
eval { |
| 44 |
my $s4_res = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e', inc => 'nothing-here' }); |
| 45 |
exit_if_mb_busy($s4_res); |
| 46 |
}; |
| 47 |
like($@, qr/not a valid.*inc.*subquery/i); |
| 48 |
sleep(1); |
| 49 |
|
| 50 |
my $s5_res = $ws->search(artist => { artist => 'Coldplay' }); |
| 51 |
exit_if_mb_busy($s5_res); |
| 52 |
ok($s5_res->{artists}); |
| 53 |
ok($s5_res->{artists}->[0]->{name} eq 'Coldplay'); |
| 54 |
ok($s5_res->{artists}->[0]->{score} eq '100'); |
| 55 |
sleep(1); |
| 56 |
|
| 57 |
my $s6_res = $ws->search(artist => { artist => 'Van Halen', type => 'group' }); |
| 58 |
exit_if_mb_busy($s6_res); |
| 59 |
ok($s6_res->{count} >= 1); |
| 60 |
ok($s6_res->{artists}->[0]->{type} eq 'Group'); |
| 61 |
ok($s6_res->{artists}->[0]->{id} eq 'b665b768-0d83-4363-950c-31ed39317c15'); |
| 62 |
sleep(1); |
| 63 |
|
| 64 |
my $s7_res = $ws->search(artist => { artist => 'Ryan Adams', type => 'person' }); |
| 65 |
exit_if_mb_busy($s7_res); |
| 66 |
ok($s7_res->{artists}->[0]->{'sort-name'} eq 'Adams, Ryan'); |
| 67 |
sleep(1); |
| 68 |
|
| 69 |
my $s8_res = $ws->search(artist => { artist => 'red' }); |
| 70 |
exit_if_mb_busy($s8_res); |
| 71 |
ok($s8_res->{count} >= 1700); |
| 72 |
ok($s8_res->{offset} == 0); |
| 73 |
sleep(1); |
| 74 |
|
| 75 |
my $s9_res = $ws->search(artist => { artist => 'red', offset => 30 }); |
| 76 |
exit_if_mb_busy($s9_res); |
| 77 |
ok($s9_res->{count} >= 1700); |
| 78 |
ok($s9_res->{offset} == 30); |
| 79 |
sleep(1); |
| 80 |
|
| 81 |
# XML TESTS |
| 82 |
my $s1_dom = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e', fmt => 'xml' }); |
| 83 |
exit_if_mb_busy($s1_dom); |
| 84 |
ok($s1_dom->at('sort-name')->text eq 'Prince'); |
| 85 |
sleep(1); |
| 86 |
|
| 87 |
my $s2_dom = $ws->search(artist => { artist => 'Ryan Adams', type => 'person', fmt => 'xml' }); |
| 88 |
exit_if_mb_busy($s2_dom); |
| 89 |
ok($s2_dom->at('country')->text eq 'US'); |
| 90 |
|
| 91 |
done_testing(); |