-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBS-13781: Support browsing genres by collection in the API
We added the feature in the last schema change but I completely forgot the WS side of it. This implements it, plus some tests.
- Loading branch information
1 parent
cfa2ee4
commit f427de5
Showing
4 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
t/lib/t/MusicBrainz/Server/Controller/WS/2/BrowseGenres.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package t::MusicBrainz::Server::Controller::WS::2::BrowseGenres; | ||
use utf8; | ||
use strict; | ||
use warnings; | ||
|
||
use Test::Routine; | ||
use Test::More; | ||
use HTTP::Status qw( :constants ); | ||
|
||
with 't::Mechanize', 't::Context'; | ||
|
||
use MusicBrainz::Server::Test::WS qw( | ||
ws2_test_xml | ||
ws2_test_xml_forbidden | ||
ws2_test_xml_unauthorized | ||
); | ||
|
||
test all => sub { | ||
|
||
my $test = shift; | ||
my $c = $test->c; | ||
|
||
MusicBrainz::Server::Test->prepare_test_database($c, '+webservice'); | ||
|
||
ws2_test_xml 'browse genres via public collection', | ||
'/genre?collection=7749c811-d77c-4ea5-9a9e-e2a4e7ae0d1a' => | ||
'<?xml version="1.0"?> | ||
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#"> | ||
<genre-list count="1"> | ||
<genre id="51cfaac4-6696-480b-8f1b-27cfc789109c"> | ||
<name>grime</name> | ||
<disambiguation>stuff</disambiguation> | ||
</genre> | ||
</genre-list> | ||
</metadata>'; | ||
|
||
ws2_test_xml 'browse genres via private collection', | ||
'/genre?collection=7749c811-d77c-4ea5-9a9e-e2a4e7ae0d1b' => | ||
'<?xml version="1.0"?> | ||
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#"> | ||
<genre-list count="1"> | ||
<genre id="51cfaac4-6696-480b-8f1b-27cfc789109c"> | ||
<name>grime</name> | ||
<disambiguation>stuff</disambiguation> | ||
</genre> | ||
</genre-list> | ||
</metadata>', | ||
{ username => 'the-anti-kuno', password => 'notreally' }; | ||
|
||
ws2_test_xml_forbidden 'browse genres via private collection, no credentials', | ||
'/genre?collection=7749c811-d77c-4ea5-9a9e-e2a4e7ae0d1b'; | ||
|
||
ws2_test_xml_unauthorized 'browse genres via private collection, bad credentials', | ||
'/genre?collection=7749c811-d77c-4ea5-9a9e-e2a4e7ae0d1b', | ||
{ username => 'the-anti-kuno', password => 'idk' }; | ||
|
||
my $res = $test->mech->get('/ws/2/genre?collection=3c37b9fa-a6c1-37d2-9e90-657a116d337c&limit=-1'); | ||
is($res->code, HTTP_BAD_REQUEST); | ||
|
||
$res = $test->mech->get('/ws/2/genre?collection=3c37b9fa-a6c1-37d2-9e90-657a116d337c&offset=a+bit'); | ||
is($res->code, HTTP_BAD_REQUEST); | ||
|
||
$res = $test->mech->get('/ws/2/genre?collection=3c37b9fa-a6c1-37d2-9e90-657a116d337c&limit=10&offset=-1'); | ||
is($res->code, HTTP_BAD_REQUEST); | ||
|
||
}; | ||
|
||
1; | ||
|
59 changes: 59 additions & 0 deletions
59
t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/BrowseGenres.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package t::MusicBrainz::Server::Controller::WS::2::JSON::BrowseGenres; | ||
use utf8; | ||
use strict; | ||
use warnings; | ||
|
||
use JSON; | ||
use Test::Routine; | ||
use MusicBrainz::Server::Test ws_test_json => { | ||
version => 2, | ||
}; | ||
use MusicBrainz::Server::Test::WS qw( | ||
ws2_test_json_forbidden | ||
ws2_test_json_unauthorized | ||
); | ||
|
||
with 't::Mechanize', 't::Context'; | ||
|
||
test 'browse genres via collection' => sub { | ||
|
||
MusicBrainz::Server::Test->prepare_test_database(shift->c, '+webservice'); | ||
|
||
ws_test_json 'browse genres via public collection', | ||
'/genre?collection=7749c811-d77c-4ea5-9a9e-e2a4e7ae0d1a' => | ||
{ | ||
'genre-offset' => 0, | ||
'genre-count' => 1, | ||
genres => [ | ||
{ | ||
id => '51cfaac4-6696-480b-8f1b-27cfc789109c', | ||
name => 'grime', | ||
disambiguation => 'stuff', | ||
}], | ||
}; | ||
|
||
ws_test_json 'browse genres via private collection', | ||
'/genre?collection=7749c811-d77c-4ea5-9a9e-e2a4e7ae0d1b' => | ||
{ | ||
'genre-offset' => 0, | ||
'genre-count' => 1, | ||
genres => [ | ||
{ | ||
id => '51cfaac4-6696-480b-8f1b-27cfc789109c', | ||
name => 'grime', | ||
disambiguation => 'stuff', | ||
}], | ||
}, | ||
{ username => 'the-anti-kuno', password => 'notreally' }; | ||
|
||
|
||
ws2_test_json_forbidden 'browse genres via private collection, no credentials', | ||
'/genre?collection=7749c811-d77c-4ea5-9a9e-e2a4e7ae0d1b'; | ||
|
||
ws2_test_json_unauthorized 'browse genres via private collection, bad credentials', | ||
'/genre?collection=7749c811-d77c-4ea5-9a9e-e2a4e7ae0d1b', | ||
{ username => 'the-anti-kuno', password => 'idk' }; | ||
|
||
}; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters