def from_dict(cls, data: Dict): try: correction = data.pop("correction") data = correction.pop("track") except KeyError: pass if isinstance(data["artist"], str): data["artist"] = dict(name=data["artist"]) data.update( dict(name=str(data["name"]), artist=Artist.from_dict(data["artist"]))) if "image" in data: data["image"] = list(map(Image.from_dict, data["image"])) if "top_tags" in data: data["top_tags"] = list(map(Tag.from_dict, data["top_tags"]["tag"])) if "wiki" in data: data["wiki"] = Wiki.from_dict(data["wiki"]) if "album" in data: data["album"] = Album.from_dict(data["album"]) if "attr" in data: data.update(data.pop("attr")) if "date" in data: date = data.pop("date") if isinstance(date, dict) and "timestamp" not in data: date.pop("text") data.update(date) return super(Track, cls).from_dict(data)
def setUp(self): self.album = Album.from_dict( dict( name="A Night at the Opera", artist="Queen", mbid="6defd963-fe91-4550-b18e-82c685603c2b", )) super(AlbumTests, self).setUp()
def setUp(self): self.album = Album.from_dict( { "name": "A Night at the Opera", "artist": "Queen", "mbid": "6defd963-fe91-4550-b18e-82c685603c2b", } ) super().setUp()
def test_search(self): result = Album.search("fire") expected_params = { "album": "fire", "limit": 50, "method": "album.search", "page": 1, } self.assertEqual(expected_params, result.params) self.assertIsInstance(result, ListModel) self.assertFixtureEqual("album/search", result.to_dict())
def test_find_by_mbid(self): result = Album.find_by_mbid("6defd963-fe91-4550-b18e-82c685603c2b") expected_params = { "autocorrect": True, "lang": "en", "mbid": "6defd963-fe91-4550-b18e-82c685603c2b", "method": "album.getInfo", "username": None, } self.assertEqual(expected_params, result.params) self.assertIsInstance(result, Album) self.assertFixtureEqual("album/find_by_mbid", result.to_dict())
def test_find(self): result = Album.find(artist="Mumford & Sons", album="Delta") expected_params = { "album": "Delta", "artist": "Mumford & Sons", "autocorrect": True, "lang": "en", "method": "album.getInfo", "username": None, } self.assertEqual(expected_params, result.params) self.assertIsInstance(result, Album) self.assertFixtureEqual("album/find", result.to_dict())