def test_read(self, req):

        mock = unittest.mock.MagicMock()
        mock.status_code = 200
        mock.text = json.dumps(return_json)
        req.return_value = mock
        e = troi.musicbrainz.genre_lookup.GenreLookupElement()

        r = [troi.Recording(mbid='00440193-f84c-4e3d-b23c-a96d21c050e6'),
             troi.Recording(mbid='0222ff68-4590-49b7-b063-c625e0f735ed'),
             troi.Recording(mbid='1636e7a9-229d-446d-aa81-e33071b42d7a')]
        entities = e.read([r])
        req.assert_called_with(e.SERVER_URL, json=[
            {'[recording_mbid]': '00440193-f84c-4e3d-b23c-a96d21c050e6'},
            {'[recording_mbid]': '0222ff68-4590-49b7-b063-c625e0f735ed'},
            {'[recording_mbid]': '1636e7a9-229d-446d-aa81-e33071b42d7a'}
        ])

        assert len(entities) == 3
        assert entities[0].musicbrainz['tags'] == ['downtempo']
        assert entities[0].musicbrainz['genres'] == ['downtempo']
        assert entities[1].musicbrainz['tags'] == []
        assert entities[1].musicbrainz['genres'] == []
        assert entities[2].musicbrainz['tags'] == ['hip hop', 'hip-hop', 'hip-hop rap']
        assert entities[2].musicbrainz['genres'] == ['hip hop']
Esempio n. 2
0
    def test_read(self, req):

        mock = unittest.mock.MagicMock()
        mock.status_code = 200
        mock.text = json.dumps(return_json)
        req.return_value = mock
        e = troi.musicbrainz.recording_lookup.RecordingLookupElement()

        inputs = [
            troi.Recording(mbid="a96bf3b6-651d-49f4-9a89-eee27cecc18e"),
            troi.Recording(mbid="ec5b8aa9-7483-4791-a185-1f599a0cdc35")
        ]
        entities = e.read([inputs])
        req.assert_called_with(e.SERVER_URL % len(inputs), json=request_json)

        assert len(entities) == 2
        assert entities[0].name == "Sour Times"
        assert entities[0].length == 253000
        assert entities[0].artist.name == "Portishead"
        assert entities[0].artist.artist_credit_id == 65
        assert entities[0].mbid == "a96bf3b6-651d-49f4-9a89-eee27cecc18e"

        assert entities[1].name == "Blue Angel"
        assert entities[1].length == 275333
        assert entities[1].artist.name == "Squirrel Nut Zippers"
        assert entities[1].artist.artist_credit_id == 11
        assert entities[1].mbid == "cfa47c9b-f12f-4f9c-a6da-22a9355d6125"
Esempio n. 3
0
    def test_read_remove_unmatched(self, req):

        mock = unittest.mock.MagicMock()
        mock.status_code = 200
        mock.text = "{}"
        req.return_value = mock
        e = troi.musicbrainz.msb_mapping.MSBMappingLookupElement(True)

        r = [ troi.Recording("track not found", artist=troi.Artist("artist not found")) ]
        entities = e.read([r])
        assert len(entities) == 0
    def test_read_keep_unmatched(self, req):

        mock = unittest.mock.MagicMock()
        mock.status_code = 200
        mock.text = json.dumps(return_json_keep_unmatched)
        req.return_value = mock
        e = troi.musicbrainz.year_lookup.YearLookupElement(skip_not_found=False)

        r = [ troi.Recording("trigger hippie", artist=troi.Artist("morcheeba")) ]
        entities = e.read([r])
        assert len(entities) == 1
        assert entities[0].artist.name == "morcheeba"
        assert entities[0].name == "trigger hippie"
        assert entities[0].year is None
    def test_read(self, req):

        mock = unittest.mock.MagicMock()
        mock.status_code = 200
        mock.text = json.dumps(return_json)
        req.return_value = mock
        e = troi.musicbrainz.year_lookup.YearLookupElement()

        r = [ troi.Recording("trigger hippie", artist=troi.Artist("morcheeba")) ]
        entities = e.read([r])
        req.assert_called_with(e.SERVER_URL, json=[{ '[recording_name]': 'trigger hippie', '[artist_credit_name]': 'morcheeba' }])

        assert len(entities) == 1
        assert entities[0].artist.name == "morcheeba"
        assert entities[0].name == "trigger hippie"
        assert entities[0].year == 1997
Esempio n. 6
0
    def test_read(self, req):

        mock = unittest.mock.MagicMock()
        mock.status_code = 200
        mock.text = return_json
        req.return_value = mock
        e = troi.musicbrainz.msb_mapping.MSBMappingLookupElement()

        r = [ troi.Recording("trigger hippie", artist=troi.Artist("morcheeba")) ]
        entities = e.read([r])
        req.assert_called_with(e.SERVER_URL +
            "?[msb_artist_credit_name]=morcheeba&[msb_recording_name]=trigger%20hippie")

        assert len(entities) == 1
        assert entities[0].artist.artist_credit_id == 963
        assert entities[0].artist.name == "Morcheeba"
        assert entities[0].release.mbid == "9db51cd6-38f6-3b42-8ad5-559963d68f35"
        assert entities[0].release.name == "Who Can You Trust?"
        assert entities[0].mbid == "97e69767-5d34-4c97-b36a-f3b2b1ef9dae"
        assert entities[0].name == "Trigger Hippie"