@@ -757,79 +757,6 @@ def test_alias(self):
757
757
758
758
759
759
class MBLibraryTest (MusicBrainzTestCase ):
760
- def test_match_track (self ):
761
- with mock .patch ("musicbrainzngs.search_recordings" ) as p :
762
- p .return_value = {
763
- "recording-list" : [
764
- {
765
- "title" : "foo" ,
766
- "id" : "bar" ,
767
- "length" : 42 ,
768
- }
769
- ],
770
- }
771
- ti = list (self .mb .item_candidates (None , "hello" , "there" ))[0 ]
772
-
773
- p .assert_called_with (artist = "hello" , recording = "there" , limit = 5 )
774
- assert ti .title == "foo"
775
- assert ti .track_id == "bar"
776
-
777
- def test_candidates (self ):
778
- mbid = "d2a6f856-b553-40a0-ac54-a321e8e2da99"
779
- with mock .patch ("musicbrainzngs.search_releases" ) as sp :
780
- sp .return_value = {
781
- "release-list" : [
782
- {
783
- "id" : mbid ,
784
- }
785
- ],
786
- }
787
- with mock .patch ("musicbrainzngs.get_release_by_id" ) as gp :
788
- gp .return_value = {
789
- "release" : {
790
- "title" : "hi" ,
791
- "id" : mbid ,
792
- "status" : "status" ,
793
- "medium-list" : [
794
- {
795
- "track-list" : [
796
- {
797
- "id" : "baz" ,
798
- "recording" : {
799
- "title" : "foo" ,
800
- "id" : "bar" ,
801
- "length" : 42 ,
802
- },
803
- "position" : 9 ,
804
- "number" : "A1" ,
805
- }
806
- ],
807
- "position" : 5 ,
808
- }
809
- ],
810
- "artist-credit" : [
811
- {
812
- "artist" : {
813
- "name" : "some-artist" ,
814
- "id" : "some-id" ,
815
- },
816
- }
817
- ],
818
- "release-group" : {
819
- "id" : "another-id" ,
820
- },
821
- }
822
- }
823
-
824
- ai = list (self .mb .candidates ([], "hello" , "there" , False ))[0 ]
825
-
826
- sp .assert_called_with (
827
- artist = "hello" , release = "there" , tracks = "0" , limit = 5
828
- )
829
- gp .assert_called_with (mbid , mock .ANY )
830
- assert ai .tracks [0 ].title == "foo"
831
- assert ai .album == "hi"
832
-
833
760
def test_follow_pseudo_releases (self ):
834
761
side_effect = [
835
762
{
@@ -1061,37 +988,91 @@ def test_pseudo_releases_with_unsupported_links(self):
1061
988
class TestMusicBrainzPlugin (PluginMixin ):
1062
989
plugin = "musicbrainz"
1063
990
991
+ mbid = "d2a6f856-b553-40a0-ac54-a321e8e2da99"
992
+ RECORDING = {"title" : "foo" , "id" : "bar" , "length" : 42 }
993
+
1064
994
@pytest .fixture
1065
- def mb_plugin (self , plugin_config ):
995
+ def plugin_config (self ):
996
+ return {}
997
+
998
+ @pytest .fixture
999
+ def mb (self , plugin_config ):
1066
1000
self .config [self .plugin ].set (plugin_config )
1067
1001
1068
1002
return musicbrainz .MusicBrainzPlugin ()
1069
1003
1070
1004
@pytest .mark .parametrize (
1071
1005
"plugin_config,va_likely,expected_additional_criteria" ,
1072
1006
[
1073
- ({}, False , {"artist" : "artist " }),
1007
+ ({}, False , {"artist" : "Artist " }),
1074
1008
({}, True , {"arid" : "89ad4ac3-39f7-470e-963a-56509c546377" }),
1075
1009
(
1076
1010
{"extra_tags" : ["label" , "catalognum" ]},
1077
1011
False ,
1078
- {"artist" : "artist " , "label" : "abc" , "catno" : "abc123 " },
1012
+ {"artist" : "Artist " , "label" : "abc" , "catno" : "ABC123 " },
1079
1013
),
1080
1014
],
1081
1015
)
1082
1016
def test_get_album_criteria (
1083
- self , mb_plugin , va_likely , expected_additional_criteria
1017
+ self , mb , va_likely , expected_additional_criteria
1084
1018
):
1085
1019
items = [
1086
1020
Item (catalognum = "ABC 123" , label = "abc" ),
1087
1021
Item (catalognum = "ABC 123" , label = "abc" ),
1088
1022
Item (catalognum = "ABC 123" , label = "def" ),
1089
1023
]
1090
1024
1091
- assert mb_plugin .get_album_criteria (
1092
- items , "Artist " , " Album" , va_likely
1093
- ) == {
1094
- "release" : "album" ,
1025
+ assert mb .get_album_criteria (items , "Artist " , " Album" , va_likely ) == {
1026
+ "release" : " Album" ,
1095
1027
"tracks" : str (len (items )),
1096
1028
** expected_additional_criteria ,
1097
1029
}
1030
+
1031
+ def test_item_candidates (self , monkeypatch , mb ):
1032
+ monkeypatch .setattr (
1033
+ "musicbrainzngs.search_recordings" ,
1034
+ lambda * _ , ** __ : {"recording-list" : [self .RECORDING ]},
1035
+ )
1036
+
1037
+ candidates = list (mb .item_candidates (Item (), "hello" , "there" ))
1038
+
1039
+ assert len (candidates ) == 1
1040
+ assert candidates [0 ].track_id == self .RECORDING ["id" ]
1041
+
1042
+ def test_candidates (self , monkeypatch , mb ):
1043
+ monkeypatch .setattr (
1044
+ "musicbrainzngs.search_releases" ,
1045
+ lambda * _ , ** __ : {"release-list" : [{"id" : self .mbid }]},
1046
+ )
1047
+ monkeypatch .setattr (
1048
+ "musicbrainzngs.get_release_by_id" ,
1049
+ lambda * _ , ** __ : {
1050
+ "release" : {
1051
+ "title" : "hi" ,
1052
+ "id" : self .mbid ,
1053
+ "status" : "status" ,
1054
+ "medium-list" : [
1055
+ {
1056
+ "track-list" : [
1057
+ {
1058
+ "id" : "baz" ,
1059
+ "recording" : self .RECORDING ,
1060
+ "position" : 9 ,
1061
+ "number" : "A1" ,
1062
+ }
1063
+ ],
1064
+ "position" : 5 ,
1065
+ }
1066
+ ],
1067
+ "artist-credit" : [
1068
+ {"artist" : {"name" : "some-artist" , "id" : "some-id" }}
1069
+ ],
1070
+ "release-group" : {"id" : "another-id" },
1071
+ }
1072
+ },
1073
+ )
1074
+ candidates = list (mb .candidates ([], "hello" , "there" , False ))
1075
+
1076
+ assert len (candidates ) == 1
1077
+ assert candidates [0 ].tracks [0 ].track_id == self .RECORDING ["id" ]
1078
+ assert candidates [0 ].album == "hi"
0 commit comments