def testReleaseFull(self): f = os.path.join(VALID_RELEASE_DIR, 'Little_Earthquakes_2.xml') md = MbXmlParser().parse(f) release = md.getRelease() self.failIf( release is None ) self.assertEquals(release.getId(), makeId('02232360-337e-4a3f-ad20-6cdd4c34288c')) self.assertEquals(release.getArtist().getName(), 'Tori Amos') events = release.getReleaseEventsAsDict() self.assertEquals(len(events), 3) self.assertEquals(events['GB'], '1992-01-13') self.assertEquals(events['DE'], '1992-01-17') self.assertEquals(events['US'], '1992-02-25') date = release.getEarliestReleaseDate() self.assertEquals(date, '1992-01-13') event = release.getEarliestReleaseEvent() self.assertEquals(event.date, date) self.assertEquals(event.country, 'GB') discs = release.getDiscs() self.assertEquals(len(discs), 3) self.assertEquals(discs[0].getId(), 'ILKp3.bZmvoMO7wSrq1cw7WatfA-') self.assertEquals(discs[1].getId(), 'ejdrdtX1ZyvCb0g6vfJejVaLIK8-') self.assertEquals(discs[2].getId(), 'Y96eDQZbF4Z26Y5.Sxdbh3wGypo-') tracks = release.getTracks() self.assertEquals(len(tracks), 12) self.assertEquals(tracks[0].getTitle(), 'Crucify') self.assertEquals(tracks[4].getTitle(), 'Winter')
def testReleaseGroupFull(self): f = os.path.join(RELEASEGROUP_DIR, 'The_Cure_1.xml') md = MbXmlParser().parse(f) releaseGroup = md.getReleaseGroup() self.failIf(releaseGroup is None) releases = releaseGroup.getReleases() self.failIf(releases is None) self.assertEquals(len(releases), 4) # Check releases, which are in no particular order. expectedIds = [ 'd984e1a3-7281-46bb-ad8b-1478a00f2fbf', 'c100a398-3132-48a8-a5fc-c3e908ac17dc', '24bec892-b21d-47d8-a288-dc6450152574', '61a4ec51-fa34-4757-85d7-83231776ed14'] actualIds = [release.id[-36:] for release in releases] for expectedId in expectedIds: self.assert_(expectedId in actualIds) # Check artist self.assertEquals(releaseGroup.getArtist().getName(), 'The Cure') self.assertEquals(releaseGroup.getArtist().id[-36:], '69ee3720-a7cb-4402-b48d-a02c366f2bcf')
def testTrackFull(self): f = os.path.join(VALID_TRACK_DIR, 'Silent_All_These_Years_4.xml') md = MbXmlParser().parse(f) track = md.getTrack() self.failIf( track is None ) self.assertEquals(track.getTitle(), 'Silent All These Years') self.assertEquals(track.getDuration(), 253466) artist = track.getArtist() self.failIf( artist is None ) self.assertEquals(artist.getId(), makeId('c0b2500e-0cef-4130-869d-732b23ed9df5', 'artist')) self.assertEquals(artist.getType(), NS_MMD_1 + 'Person') self.assertEquals(artist.getName(), 'Tori Amos') self.assertEquals(artist.getSortName(), 'Amos, Tori') puids = track.getPuids() self.assertEquals(len(puids), 7) self.assertEquals(puids[0], 'c2a2cee5-a8ca-4f89-a092-c3e1e65ab7e6') self.assertEquals(puids[6], '42ab76ea-5d42-4259-85d7-e7f2c69e4485') isrcs = track.isrcs self.assertEquals(len(isrcs), 1) self.assertEquals(isrcs[0], 'USPR37300012') releases = track.getReleases() self.assertEquals(len(releases), 1) self.assertEquals(releases[0].getTitle(), 'Little Earthquakes') self.assertEquals(releases[0].getTracksOffset(), 2)
def testSearchResults(self): f = os.path.join(RELEASEGROUP_DIR, 'search_result_1.xml') md = MbXmlParser().parse(f) releaseGroups = md.getReleaseGroupResults() self.failIf(releaseGroups is None) self.assertEquals(md.getReleaseGroupResultsOffset(), 0) self.assertEquals(md.getReleaseGroupResultsCount(), 3) expectedEntries = { '963eac15-e3da-3a92-aa5c-2ec23bfb6ec2': ['Signal Morning', 100], '0bd324a3-1c90-3bdb-8ca4-4101a580c62c': ['Circulatory System', 98], 'ea7d8352-7751-30be-8490-bb6df737f47c': ['Inside Views', 90]} for result in releaseGroups: releaseGroup = result.releaseGroup self.failIf(releaseGroup is None) releaseGroupId = releaseGroup.id[-36:] self.assert_(releaseGroupId in expectedEntries) expectedTitle, expectedScore = expectedEntries[releaseGroupId] self.assertEquals(releaseGroup.title, expectedTitle) self.assertEquals(result.score, expectedScore) del expectedEntries[releaseGroupId]
def getUserRating(self, entityUri): """Return the rating a user has applied to an entity. The given parameter has to be a fully qualified MusicBrainz ID, as returned by other library functions. Note that this method only works if a valid user name and password have been set. Only the rating the authenticated user applied to the entity will be returned. If username and/or password are incorrect, an AuthenticationError is raised. This method will return a L{Rating <musicbrainz2.model.Rating>} object. @param entityUri: a string containing an absolute MB ID @raise ValueError: invalid entityUri @raise ConnectionError: couldn't connect to server @raise RequestError: invalid ID or entity @raise AuthenticationError: invalid user name and/or password """ entity = mbutils.extractEntityType(entityUri) uuid = mbutils.extractUuid(entityUri, entity) params = { 'entity': entity, 'id': uuid } stream = self._ws.get('rating', '', filter=params) try: parser = MbXmlParser() result = parser.parse(stream) except ParseError, e: raise ResponseError(str(e), e)
def testTrackBasic(self): f = os.path.join(VALID_TRACK_DIR, 'Silent_All_These_Years_1.xml') md = MbXmlParser().parse(f) track = md.getTrack() self.failIf( track is None ) self.assertEquals(track.getTitle(), 'Silent All These Years') self.assertEquals(track.getDuration(), 253466)
def getTrack(self, filter): params = filter.createParameters() stream = self._ws.post("track", "", urllib.urlencode(params, True)) try: parser = MbXmlParser() return parser.parse(stream).getTrack() except ParseError, e: raise ResponseError(str(e), e)
def testIncomplete(self): f = os.path.join(VALID_LABEL_DIR, 'Atlantic_Records_3.xml') md = MbXmlParser().parse(f) label = md.getLabel() self.failIf( label is None ) self.assertEquals(label.id, makeId('50c384a2-0b44-401b-b893-8181173339c7')) self.assertEquals(label.code, None)
def testTags(self): f = os.path.join(VALID_LABEL_DIR, 'Atlantic_Records_3.xml') md = MbXmlParser().parse(f) label = md.getLabel() self.failIf( label is None ) self.assertEquals(label.getTag('american').count, None) self.assertEquals(label.getTag('jazz').count, None) self.assertEquals(label.getTag('blues').count, None)
def testTags(self): f = os.path.join(VALID_ARTIST_DIR, 'Tchaikovsky-2.xml') md = MbXmlParser().parse(f) artist = md.getArtist() self.failIf( artist is None ) self.assertEquals(artist.getTag('classical').count, 100) self.assertEquals(artist.getTag('russian').count, 60) self.assertEquals(artist.getTag('romantic era').count, 40) self.assertEquals(artist.getTag('composer').count, 120)
def testReleaseGroupBasic(self): f = os.path.join(RELEASEGROUP_DIR, 'The_Cure_1.xml') md = MbXmlParser().parse(f) releaseGroup = md.getReleaseGroup() self.failIf(releaseGroup is None) self.assertEquals(releaseGroup.getId(), makeId('c6a62b78-70f7-44f7-b159-064f6b7ba03a')) self.assertEquals(releaseGroup.getTitle(), 'The Cure') self.assertEquals(releaseGroup.getType(), NS_MMD_1 + 'Album')
def testArtistBasic(self): f = os.path.join(VALID_ARTIST_DIR, 'Tori_Amos_1.xml') md = MbXmlParser().parse(f) artist = md.getArtist() self.failIf( artist is None ) self.assertEquals(artist.getName(), 'Tori Amos') self.assertEquals(artist.getSortName(), 'Amos, Tori') self.assertEquals(artist.getBeginDate(), '1963-08-22') self.assertEquals(len(artist.getReleases()), 0)
def testTags(self): f = os.path.join(VALID_RELEASE_DIR, 'Highway_61_Revisited_2.xml') md = MbXmlParser().parse(f) release = md.getRelease() self.failIf( release is None ) self.assertEquals(release.getTag('rock').count, 100) self.assertEquals(release.getTag('blues rock').count, 40) self.assertEquals(release.getTag('folk rock').count, 40) self.assertEquals(release.getTag('dylan').count, 4)
def testIncompleteReleaseEvent(self): f = os.path.join(VALID_RELEASE_DIR, 'Under_the_Pink_1.xml') md = MbXmlParser().parse(f) release = md.getRelease() self.failIf( release is None ) self.assertEquals(release.getTitle(), 'Under the Pink') events = release.getReleaseEvents() self.assertEquals(len(events), 1) self.assertEquals(events[0].getDate(), '1994-01-28')
def testSearchResults(self): f = os.path.join(VALID_TRACK_DIR, 'search_result_1.xml') md = MbXmlParser().parse(f) self.assertEquals(md.trackResultsOffset, 7) self.assertEquals(md.trackResultsCount, 100) results = md.getTrackResults() self.assertEquals(len(results), 3) self.assertEquals(results[0].getScore(), 100) track1 = results[0].getTrack() self.assertEquals(track1.getTitle(), 'Little Earthquakes')
def testReleaseGroup(self): f = os.path.join(VALID_RELEASE_DIR, 'Under_the_Pink_2.xml') md = MbXmlParser().parse(f) release = md.getRelease() self.failIf(release is None) self.assertEquals(release.getTitle(), 'Under the Pink') releaseGroup = release.getReleaseGroup() self.failIf(releaseGroup is None) self.assertEquals(releaseGroup.id[-36:], 'ef2b891f-ca73-3e14-b38b-a68699dab8c4') self.assertEquals(releaseGroup.getTitle(), 'Under the Pink') self.assertEquals(releaseGroup.getType(), NS_MMD_1 + 'Album')
def testLabelBasic(self): f = os.path.join(VALID_LABEL_DIR, 'Atlantic_Records_1.xml') md = MbXmlParser().parse(f) label = md.getLabel() self.failIf( label is None ) self.assertEquals(label.id, makeId('50c384a2-0b44-401b-b893-8181173339c7')) self.assertEquals(label.type, NS_MMD_1 + 'OriginalProduction') self.assertEquals(label.name, 'Atlantic Records') self.assertEquals(label.beginDate, '1947') self.assertEquals(label.endDate, None) self.assertEquals(label.country, 'US') self.assertEquals(label.code, '121')
def testReleaseBasic(self): f = os.path.join(VALID_RELEASE_DIR, 'Little_Earthquakes_1.xml') md = MbXmlParser().parse(f) release = md.getRelease() self.failIf( release is None ) self.assertEquals(release.getId(), makeId('02232360-337e-4a3f-ad20-6cdd4c34288c')) self.assertEquals(release.getTitle(), 'Little Earthquakes') self.assertEquals(release.getTextLanguage(), 'ENG') self.assertEquals(release.getTextScript(), 'Latn') self.assertEquals(len(release.getTypes()), 2) self.assert_(NS_MMD_1 + 'Album' in release.getTypes()) self.assert_(NS_MMD_1 + 'Official' in release.getTypes())
def testUser(self): f = os.path.join(VALID_USER_DIR, 'User_1.xml') md = MbXmlParser().parse(f) userList = md.getUserList() self.assertEquals(len(userList), 1) user = userList[0] self.failIf( user is None ) self.assertEquals(user.getName(), 'matt') self.assertEquals(user.getShowNag(), False) types = user.getTypes() self.assertEquals(len(types), 2) self.assert_( NS_EXT_1 + 'AutoEditor' in types ) self.assert_( NS_EXT_1 + 'RelationshipEditor' in types )
def testReleaseRelations(self): f = os.path.join(VALID_RELEASE_DIR, 'Highway_61_Revisited_1.xml') md = MbXmlParser().parse(f) release = md.getRelease() self.failIf( release is None ) self.assertEquals(release.getId(), makeId('d61a2bd9-81ac-4023-bd22-1c884d4a176c')) (rel1, rel2) = release.getRelations(Relation.TO_URL) self.assertEquals(rel1.getTargetId(), 'http://en.wikipedia.org/wiki/Highway_61_Revisited') self.assertEquals(rel1.getDirection(), Relation.DIR_NONE) self.assertEquals(rel2.getTargetId(), 'http://www.amazon.com/gp/product/B0000024SI')
def _getFromWebService(self, entity, id_, include=None, filter=None): if filter is None: filterParams = [ ] else: filterParams = filter.createParameters() if include is None: includeParams = [ ] else: includeParams = include.createIncludeTags() stream = self._ws.get(entity, id_, includeParams, filterParams) try: parser = MbXmlParser() return parser.parse(stream) except ParseError, e: raise ResponseError(str(e), e)
def testVariousArtistsRelease(self): f = os.path.join(VALID_RELEASE_DIR, 'Mission_Impossible_2.xml') md = MbXmlParser().parse(f) release = md.getRelease() self.failIf( release is None ) artistId = release.getArtist().getId() self.assertEquals(artistId, VARIOUS_ARTISTS_ID) events = release.getReleaseEventsAsDict() self.assertEquals(len(events), 1) self.assertEquals(events['EU'], '2000') track14 = release.getTracks()[14] self.assertEquals(track14.getTitle(), 'Carnival') self.assertEquals(track14.getArtist().getName(), 'Tori Amos')
def testAliases(self): f = os.path.join(VALID_ARTIST_DIR, 'Tori_Amos_4.xml') md = MbXmlParser().parse(f) artist = md.getArtist() self.failIf( artist is None ) self.assertEquals(artist.getDisambiguation(), 'yes, that one') self.assertEquals(artist.getName(), 'Tori Amos') self.assertEquals(artist.getUniqueName(), 'Tori Amos (yes, that one)') aliases = artist.getAliases() self.assertEquals(len(aliases), 3) self.assertEquals(aliases[0].getValue(), 'Myra Ellen Amos') self.assertEquals(aliases[0].getScript(), 'Latn') self.assertEquals(aliases[1].getValue(), 'Myra Amos') self.assertEquals(aliases[2].getValue(), 'Torie Amos') self.assertEquals(aliases[2].getType(), NS_MMD_1 + 'Misspelling')
def testReleaseEvents(self): f = os.path.join(VALID_RELEASE_DIR, 'Under_the_Pink_3.xml') md = MbXmlParser().parse(f) release = md.getRelease() self.failIf( release is None ) self.assertEquals(release.getTitle(), 'Under the Pink') events = release.getReleaseEvents() self.assertEquals(len(events), 1) e1 = events[0] self.assertEquals(e1.date, '1994-01-31') self.assertEquals(e1.catalogNumber, '82567-2') self.assertEquals(e1.barcode, '07567825672') self.assertEquals(e1.format, ReleaseEvent.FORMAT_CD) self.failIf( e1.label is None ) self.assertEquals(e1.label.name, 'Atlantic Records')
def testArtistFull(self): f = os.path.join(VALID_ARTIST_DIR, 'Tori_Amos_2.xml') md = MbXmlParser().parse(f) artist = md.getArtist() self.failIf( artist is None ) self.assertEquals(artist.getId(), makeId('c0b2500e-0cef-4130-869d-732b23ed9df5')) self.assertEquals(artist.getName(), 'Tori Amos') self.assertEquals(artist.getSortName(), 'Amos, Tori') self.assert_(artist.getDisambiguation() is None) self.assertEquals(artist.getUniqueName(), artist.getName()) self.assertEquals(artist.getBeginDate(), '1963-08-22') self.assertEquals(len(artist.getReleases()), 3) self.assertEquals(len(artist.getReleaseGroups()), 3) release1 = artist.getReleases()[0] self.assertEquals(release1.getTitle(), 'Strange Little Girls') self.assertEquals(release1.getAsin(), 'B00005NKYQ') # Check last release in more detail. # release3 = artist.getReleases()[2] self.assertEquals(release3.getId(), makeId('290e10c5-7efc-4f60-ba2c-0dfc0208fbf5', 'release')) self.assertEquals(len(release3.getTypes()), 2) self.assert_(NS_MMD_1 + 'Album' in release3.getTypes()) self.assert_(NS_MMD_1 + 'Official' in release3.getTypes()) self.assertEquals(release3.getTitle(), 'Under the Pink') self.assertEquals(release3.getAsin(), 'B000002IXU') self.assertEquals(release3.getArtist().getId(), makeId('c0b2500e-0cef-4130-869d-732b23ed9df5')) self.failIf(release3.getReleaseGroup() is None) self.assertEquals(release3.getReleaseGroup().id[-36:], 'ef2b891f-ca73-3e14-b38b-a68699dab8c4') events = release3.getReleaseEvents() self.assertEquals(len(events), 5) self.assertEquals(events[0].getCountry(), 'DE') self.assertEquals(events[0].getDate(), '1994-01-28') self.assertEquals(events[4].getCountry(), 'AU') self.assertEquals(events[4].getDate(), '1994-11') self.assertEquals(release3.getEarliestReleaseDate(), '1994-01-28')
def testSearchResults(self): f = os.path.join(VALID_LABEL_DIR, 'search_result_1.xml') md = MbXmlParser().parse(f) self.assertEquals(md.labelResultsOffset, 0) self.assertEquals(md.labelResultsCount, 2) self.assertEquals(md.getLabelResultsOffset(), 0) self.assertEquals(md.getLabelResultsCount(), 2) results = md.labelResults self.assertEquals(len(results), 2) self.assertEquals(results[0].score, 100) label1 = results[0].label self.assertEquals(label1.name, 'Atlantic Records') self.assertEquals(results[1].score, 46) label2 = results[1].label self.assertEquals(label2.name, 'DRO Atlantic')
def testEmptyType(self): f = os.path.join(RELEASEGROUP_DIR, 'The_Cure_1.xml') md1 = MbXmlParser().parse(f) releaseGroup1 = md1.getReleaseGroup() releaseGroup1.setType(None) # Serialize. outbuffer = StringIO() MbXmlWriter().write(outbuffer, md1) inbuffer = StringIO(outbuffer.getvalue().encode('utf-8')) md2 = MbXmlParser().parse(inbuffer) # Check releaseGroup2 = md2.getReleaseGroup() self.failIf(releaseGroup2 is None) self.assertEquals(releaseGroup2.getType(), None)
def testLabelSubElements(self): f = os.path.join(VALID_LABEL_DIR, 'Atlantic_Records_2.xml') md = MbXmlParser().parse(f) label = md.getLabel() self.failIf( label is None ) self.assertEquals(label.type, NS_MMD_1 + 'Distributor') self.assertEquals(label.name, 'Atlantic Records') self.assertEquals(label.sortName, 'AR SortName') self.assertEquals(label.disambiguation, 'fake') self.assertEquals(label.beginDate, '1947') self.assertEquals(label.endDate, '2047') self.assertEquals(label.country, 'US') self.assertEquals(label.code, '121') self.assertEquals(len(label.aliases), 1) alias = label.aliases[0] self.assertEquals(alias.value, 'Atlantic Rec.') self.assertEquals(label.getUniqueName(), 'Atlantic Records (fake)')
def testReleaseGroups(self): f = os.path.join(VALID_ARTIST_DIR, 'Tori_Amos_2.xml') md = MbXmlParser().parse(f) artist = md.getArtist() self.failIf(artist is None) releaseGroups = artist.getReleaseGroups() self.failIf(releaseGroups is None) self.assertEquals(len(releaseGroups), 3) expectedEntries = { 'ef2b891f-ca73-3e14-b38b-a68699dab8c4': 'Under the Pink', '1fd43909-8056-3805-b2f9-c663ce7e71e6': 'To Venus and Back', 'a69a1574-dfe3-3e2a-b499-d26d5e916041': 'Strange Little Girls'} for releaseGroup in releaseGroups: self.assertEquals(releaseGroup.getType(), NS_MMD_1 + 'Album') releaseGroupId = releaseGroup.id[-36:] self.assert_(releaseGroupId in expectedEntries) self.assertEquals(releaseGroup.getTitle(), expectedEntries[releaseGroupId]) del expectedEntries[releaseGroupId]
def testSerialize(self): # Get initial. f = os.path.join(RELEASEGROUP_DIR, 'The_Cure_1.xml') md1 = MbXmlParser().parse(f) # Serialize. outbuffer = StringIO() MbXmlWriter().write(outbuffer, md1) # Deserialize. inbuffer = StringIO(outbuffer.getvalue().encode('utf-8')) md2 = MbXmlParser().parse(inbuffer) # Check releaseGroup = md2.getReleaseGroup() self.failIf(releaseGroup is None) self.assertEquals(len(releaseGroup.getReleases()), 4) self.assertEquals(releaseGroup.getId(), makeId('c6a62b78-70f7-44f7-b159-064f6b7ba03a')) self.assertEquals(releaseGroup.getTitle(), 'The Cure') self.assertEquals(releaseGroup.getType(), NS_MMD_1 + 'Album')
def getUserCollection(self, offset=0, maxitems=100): """Get the releases that are in a user's collection A maximum of 100 items will be returned for any one call to this method. To fetch more than 100 items, use the offset parameter. @param offset: the offset to start fetching results from @param maxitems: the upper limit on items to return @return: a list of L{musicbrainz2.wsxml.ReleaseResult} objects @raise ConnectionError: couldn't connect to server @raise AuthenticationError: invalid user name and/or password """ params = { 'offset': offset, 'maxitems': maxitems } stream = self._ws.get('collection', '', filter=params) try: parser = MbXmlParser() result = parser.parse(stream) except ParseError, e: raise ResponseError(str(e), e)