musicbrainzngs-0.4/ 0000775 0001750 0001750 00000000000 12144757472 016054 5 ustar alastair alastair 0000000 0000000 musicbrainzngs-0.4/test/ 0000775 0001750 0001750 00000000000 12144757472 017033 5 ustar alastair alastair 0000000 0000000 musicbrainzngs-0.4/test/test_mbxml_search.py 0000664 0001750 0001750 00000007551 12017250751 023103 0 ustar alastair alastair 0000000 0000000 import unittest
import os
import sys
# Insert .. at the beginning of path so we use this version instead
# of something that's already been installed
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import musicbrainzngs
from musicbrainzngs import mbxml
from test import _common
class UrlTest(unittest.TestCase):
""" Test that the correct URL is generated when a search query is made """
def setUp(self):
musicbrainzngs.set_useragent("a", "1")
musicbrainzngs.set_rate_limit(False)
def testSearchArtist(self):
musicbrainzngs.search_artists("Dynamo Go")
self.assertEqual("http://musicbrainz.org/ws/2/artist/?query=Dynamo+Go", _common.opener.get_url())
def testSearchWork(self):
musicbrainzngs.search_works("Fountain City")
self.assertEqual("http://musicbrainz.org/ws/2/work/?query=Fountain+City", _common.opener.get_url())
def testSearchLabel(self):
musicbrainzngs.search_labels("Waysafe")
self.assertEqual("http://musicbrainz.org/ws/2/label/?query=Waysafe", _common.opener.get_url())
def testSearchRelease(self):
musicbrainzngs.search_releases("Affordable Pop Music")
self.assertEqual("http://musicbrainz.org/ws/2/release/?query=Affordable+Pop+Music", _common.opener.get_url())
def testSearchReleaseGroup(self):
musicbrainzngs.search_release_groups("Affordable Pop Music")
self.assertEqual("http://musicbrainz.org/ws/2/release-group/?query=Affordable+Pop+Music", _common.opener.get_url())
def testSearchRecording(self):
musicbrainzngs.search_recordings("Thief of Hearts")
self.assertEqual("http://musicbrainz.org/ws/2/recording/?query=Thief+of+Hearts", _common.opener.get_url())
class SearchArtistTest(unittest.TestCase):
def testFields(self):
fn = os.path.join(os.path.dirname(__file__), "data", "search-artist.xml")
res = mbxml.parse_message(open(fn))
self.assertEqual(25, len(res["artist-list"]))
one = res["artist-list"][0]
self.assertEqual(9, len(one.keys()))
# Score is a key that is only in search results -
# so check for it here
self.assertEqual("100", one["ext:score"])
class SearchReleaseTest(unittest.TestCase):
def testFields(self):
fn = os.path.join(os.path.dirname(__file__), "data", "search-release.xml")
res = mbxml.parse_message(open(fn))
self.assertEqual(25, len(res["release-list"]))
one = res["release-list"][0]
self.assertEqual("100", one["ext:score"])
class SearchReleaseGroupTest(unittest.TestCase):
def testFields(self):
fn = os.path.join(os.path.dirname(__file__), "data", "search-release-group.xml")
res = mbxml.parse_message(open(fn))
self.assertEqual(25, len(res["release-group-list"]))
one = res["release-group-list"][0]
self.assertEqual("100", one["ext:score"])
class SearchWorkTest(unittest.TestCase):
def testFields(self):
fn = os.path.join(os.path.dirname(__file__), "data", "search-work.xml")
res = mbxml.parse_message(open(fn))
self.assertEqual(25, len(res["work-list"]))
one = res["work-list"][0]
self.assertEqual("100", one["ext:score"])
class SearchLabelTest(unittest.TestCase):
def testFields(self):
fn = os.path.join(os.path.dirname(__file__), "data", "search-label.xml")
res = mbxml.parse_message(open(fn))
self.assertEqual(1, len(res["label-list"]))
one = res["label-list"][0]
self.assertEqual("100", one["ext:score"])
class SearchRecordingTest(unittest.TestCase):
def testFields(self):
fn = os.path.join(os.path.dirname(__file__), "data", "search-recording.xml")
res = mbxml.parse_message(open(fn))
self.assertEqual(25, len(res["recording-list"]))
one = res["recording-list"][0]
self.assertEqual("100", one["ext:score"])
musicbrainzngs-0.4/test/test_mbxml_label.py 0000664 0001750 0001750 00000002676 12104304065 022713 0 ustar alastair alastair 0000000 0000000 # Tests for parsing of label queries
import unittest
import os
import sys
# Insert .. at the beginning of path so we use this version instead
# of something that's already been installed
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import musicbrainzngs
from musicbrainzngs import mbxml
class GetLabelTest(unittest.TestCase):
def setUp(self):
self.datadir = os.path.join(os.path.dirname(__file__), "data", "label")
def testLabelAliases(self):
fn = os.path.join(self.datadir, "022fe361-596c-43a0-8e22-bad712bb9548-aliases.xml")
res = mbxml.parse_message(open(fn))
aliases = res["label"]["alias-list"]
self.assertEqual(len(aliases), 4)
a0 = aliases[0]
self.assertEqual(a0["alias"], "EMI")
self.assertEqual(a0["sort-name"], "EMI")
a1 = aliases[1]
self.assertEqual(a1["alias"], "EMI Records (UK)")
self.assertEqual(a1["sort-name"], "EMI Records (UK)")
fn = os.path.join(self.datadir, "e72fabf2-74a3-4444-a9a5-316296cbfc8d-aliases.xml")
res = mbxml.parse_message(open(fn))
aliases = res["label"]["alias-list"]
self.assertEqual(len(aliases), 1)
a0 = aliases[0]
self.assertEqual(a0["alias"], "Ki/oon Records Inc.")
self.assertEqual(a0["sort-name"], "Ki/oon Records Inc.")
self.assertEqual(a0["begin-date"], "2001-10")
self.assertEqual(a0["end-date"], "2012-04")
musicbrainzngs-0.4/test/test_getentity.py 0000664 0001750 0001750 00000005757 12017250751 022461 0 ustar alastair alastair 0000000 0000000 import unittest
import os
import sys
# Insert .. at the beginning of path so we use this version instead
# of something that's already been installed
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import musicbrainzngs
from test import _common
class UrlTest(unittest.TestCase):
""" Test that the correct URL is generated when a search query is made """
def setUp(self):
musicbrainzngs.set_useragent("a", "1")
musicbrainzngs.set_rate_limit(False)
def testGetArtist(self):
artistid = "952a4205-023d-4235-897c-6fdb6f58dfaa"
musicbrainzngs.get_artist_by_id(artistid)
self.assertEqual("http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa", _common.opener.get_url())
# Test an include
musicbrainzngs.get_artist_by_id(artistid, "recordings")
self.assertEqual("http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa?inc=recordings", _common.opener.get_url())
# More than one include
musicbrainzngs.get_artist_by_id(artistid, ["recordings", "aliases"])
expected ="http://musicbrainz.org/ws/2/artist/952a4205-023d-4235-897c-6fdb6f58dfaa?inc=recordings+aliases"
self.assertEqual(expected, _common.opener.get_url())
def testGetLabel(self):
musicbrainzngs.get_label_by_id("aab2e720-bdd2-4565-afc2-460743585f16")
self.assertEqual("http://musicbrainz.org/ws/2/label/aab2e720-bdd2-4565-afc2-460743585f16", _common.opener.get_url())
# one include
musicbrainzngs.get_label_by_id("aab2e720-bdd2-4565-afc2-460743585f16", "releases")
self.assertEqual("http://musicbrainz.org/ws/2/label/aab2e720-bdd2-4565-afc2-460743585f16?inc=releases", _common.opener.get_url())
def testGetRecording(self):
musicbrainzngs.get_recording_by_id("93468a09-9662-4886-a227-56a2ad1c5246")
self.assertEqual("http://musicbrainz.org/ws/2/recording/93468a09-9662-4886-a227-56a2ad1c5246", _common.opener.get_url())
# one include
musicbrainzngs.get_recording_by_id("93468a09-9662-4886-a227-56a2ad1c5246", includes=["artists"])
self.assertEqual("http://musicbrainz.org/ws/2/recording/93468a09-9662-4886-a227-56a2ad1c5246?inc=artists", _common.opener.get_url())
def testGetReleasegroup(self):
musicbrainzngs.get_release_group_by_id("9377d65d-ffd5-35d6-b64d-43f86ef9188d")
self.assertEqual("http://musicbrainz.org/ws/2/release-group/9377d65d-ffd5-35d6-b64d-43f86ef9188d", _common.opener.get_url())
# one include
musicbrainzngs.get_release_group_by_id("9377d65d-ffd5-35d6-b64d-43f86ef9188d", includes=["artists"])
self.assertEqual("http://musicbrainz.org/ws/2/release-group/9377d65d-ffd5-35d6-b64d-43f86ef9188d?inc=artists", _common.opener.get_url())
def testGetWork(self):
musicbrainzngs.get_work_by_id("c6dfad5a-f915-41c7-a1c0-e2b606948e69")
self.assertEqual("http://musicbrainz.org/ws/2/work/c6dfad5a-f915-41c7-a1c0-e2b606948e69", _common.opener.get_url())
musicbrainzngs-0.4/test/test_mbxml.py 0000664 0001750 0001750 00000001024 12017250751 021543 0 ustar alastair alastair 0000000 0000000 import unittest
import os
import sys
sys.path.append(os.path.abspath(".."))
from musicbrainzngs import mbxml
class MbXML(unittest.TestCase):
def testMakeBarcode(self):
expected = (b''
b'12345'
b'')
xml = mbxml.make_barcode_request({'trid':'12345'})
self.assertEqual(expected, xml)
musicbrainzngs-0.4/test/test_mbxml_artist.py 0000664 0001750 0001750 00000002456 12104304065 023136 0 ustar alastair alastair 0000000 0000000 # Tests for parsing of artist queries
import unittest
import os
import sys
# Insert .. at the beginning of path so we use this version instead
# of something that's already been installed
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import musicbrainzngs
from musicbrainzngs import mbxml
class GetArtistTest(unittest.TestCase):
def setUp(self):
self.datadir = os.path.join(os.path.dirname(__file__), "data", "artist")
def testArtistAliases(self):
fn = os.path.join(self.datadir, "0e43fe9d-c472-4b62-be9e-55f971a023e1-aliases.xml")
res = mbxml.parse_message(open(fn))
aliases = res["artist"]["alias-list"]
self.assertEqual(len(aliases), 28)
a0 = aliases[0]
self.assertEqual(a0["alias"], "Prokofief")
self.assertEqual(a0["sort-name"], "Prokofief")
a17 = aliases[17]
self.assertEqual(a17["alias"], "Sergei Sergeyevich Prokofiev")
self.assertEqual(a17["sort-name"], "Prokofiev, Sergei Sergeyevich")
self.assertEqual(a17["locale"], "en")
self.assertEqual(a17["primary"], "primary")
fn = os.path.join(self.datadir, "2736bad5-6280-4c8f-92c8-27a5e63bbab2-aliases.xml")
res = mbxml.parse_message(open(fn))
self.assertFalse("alias-list" in res["artist"])
musicbrainzngs-0.4/test/_common.py 0000664 0001750 0001750 00000002521 12017250751 021017 0 ustar alastair alastair 0000000 0000000 """Common support for the test cases."""
import time
import musicbrainzngs
from musicbrainzngs import compat
try:
from urllib2 import OpenerDirector
except ImportError:
from urllib.request import OpenerDirector
try:
import StringIO
except ImportError:
import io as StringIO
class FakeOpener(OpenerDirector):
""" A URL Opener that saves the URL requested and
returns a dummy response """
def __init__(self):
self.myurl = None
def open(self, request, body=None):
self.myurl = request.get_full_url()
self.request = request
return StringIO.StringIO("")
def get_url(self):
return self.myurl
opener = FakeOpener()
musicbrainzngs.compat.build_opener = lambda *args: opener
# Mock timing.
class Timecop(object):
"""Mocks the timing system (namely time() and sleep()) for testing.
Inspired by the Ruby timecop library.
"""
def __init__(self):
self.now = time.time()
def time(self):
return self.now
def sleep(self, amount):
self.now += amount
def install(self):
self.orig = {
'time': time.time,
'sleep': time.sleep,
}
time.time = self.time
time.sleep = self.sleep
def restore(self):
time.time = self.orig['time']
time.sleep = self.orig['sleep']
musicbrainzngs-0.4/test/test_requests.py 0000664 0001750 0001750 00000004473 12017250751 022312 0 ustar alastair alastair 0000000 0000000 import unittest
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import musicbrainzngs
from musicbrainzngs import musicbrainz
from test import _common
class ArgumentTest(unittest.TestCase):
"""Tests request methods to ensure they're enforcing general parameters
(useragent, authentication)."""
def test_no_client(self):
musicbrainzngs.set_useragent("testapp", "0.1", "test@example.org")
musicbrainz._mb_request(path="foo", client_required=False)
self.assertFalse("testapp" in _common.opener.myurl)
def test_client(self):
musicbrainzngs.set_useragent("testapp", "0.1", "test@example.org")
musicbrainz._mb_request(path="foo", client_required=True)
self.assertTrue("testapp" in _common.opener.myurl)
def test_false_useragent(self):
self.assertRaises(ValueError, musicbrainzngs.set_useragent, "", "0.1",
"test@example.org")
self.assertRaises(ValueError, musicbrainzngs.set_useragent, "test", "",
"test@example.org")
def test_missing_auth(self):
self.assertRaises(musicbrainzngs.UsageError,
musicbrainz._mb_request, path="foo", auth_required=True)
def test_missing_useragent(self):
musicbrainz._useragent = ""
self.assertRaises(musicbrainzngs.UsageError,
musicbrainz._mb_request, path="foo")
class MethodTest(unittest.TestCase):
"""Tests the various _do_mb_* methods to ensure they're setting the
using the correct HTTP method."""
def setUp(self):
musicbrainz.auth("user", "password")
def test_invalid_method(self):
self.assertRaises(ValueError, musicbrainz._mb_request, path="foo",
method="HUG")
def test_delete(self):
musicbrainz._do_mb_delete("foo")
self.assertEqual("DELETE", _common.opener.request.get_method())
def test_put(self):
musicbrainz._do_mb_put("foo")
self.assertEqual("PUT", _common.opener.request.get_method())
def test_post(self):
musicbrainz._do_mb_post("foo", "body")
self.assertEqual("POST", _common.opener.request.get_method())
def test_get(self):
musicbrainz._do_mb_query("artist", 1234, [], [])
self.assertEqual("GET", _common.opener.request.get_method())
musicbrainzngs-0.4/test/__init__.py 0000664 0001750 0001750 00000000000 12017250751 021115 0 ustar alastair alastair 0000000 0000000 musicbrainzngs-0.4/test/test_mbxml_release.py 0000664 0001750 0001750 00000012334 12017250751 023251 0 ustar alastair alastair 0000000 0000000 # Tests for parsing of release queries
import unittest
import os
import sys
# Insert .. at the beginning of path so we use this version instead
# of something that's already been installed
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import musicbrainzngs
from musicbrainzngs import mbxml
from test import _common
class UrlTest(unittest.TestCase):
""" Test that the correct URL is generated when a search query is made """
def setUp(self):
musicbrainzngs.set_useragent("test", "1")
musicbrainzngs.set_rate_limit(False)
def testGetRelease(self):
musicbrainzngs.get_release_by_id("5e3524ca-b4a1-4e51-9ba5-63ea2de8f49b")
self.assertEqual("http://musicbrainz.org/ws/2/release/5e3524ca-b4a1-4e51-9ba5-63ea2de8f49b", _common.opener.get_url())
# one include
musicbrainzngs.get_release_by_id("5e3524ca-b4a1-4e51-9ba5-63ea2de8f49b", includes=["artists"])
self.assertEqual("http://musicbrainz.org/ws/2/release/5e3524ca-b4a1-4e51-9ba5-63ea2de8f49b?inc=artists", _common.opener.get_url())
# more than one include
musicbrainzngs.get_release_by_id("5e3524ca-b4a1-4e51-9ba5-63ea2de8f49b", includes=["artists", "recordings", "artist-credits"])
expected = "http://musicbrainz.org/ws/2/release/5e3524ca-b4a1-4e51-9ba5-63ea2de8f49b?inc=artists+recordings+artist-credits"
self.assertEqual(expected, _common.opener.get_url())
class GetReleaseTest(unittest.TestCase):
def setUp(self):
self.datadir = os.path.join(os.path.dirname(__file__), "data", "release")
def testArtistCredit(self):
"""
If the artist credit is the same in the track and recording, make sure that
the information is replicated in both objects, otherwise have distinct ones.
"""
# If no artist-credit in the track, copy in the recording one
fn = os.path.join(self.datadir, "833d4c3a-2635-4b7a-83c4-4e560588f23a-recordings+artist-credits.xml")
res = mbxml.parse_message(open(fn))
tracks = res["release"]["medium-list"][0]["track-list"]
t1 = tracks[1]
self.assertEqual(t1["artist-credit"], t1["recording"]["artist-credit"])
self.assertEqual("JT Bruce", t1["artist-credit-phrase"])
self.assertEqual(t1["recording"]["artist-credit-phrase"], t1["artist-credit-phrase"])
# Recording AC is different to track AC
fn = os.path.join(self.datadir, "fbe4490e-e366-4da2-a37a-82162d2f41a9-recordings+artist-credits.xml")
res = mbxml.parse_message(open(fn))
tracks = res["release"]["medium-list"][0]["track-list"]
t1 = tracks[1]
self.assertNotEqual(t1["artist-credit"], t1["recording"]["artist-credit"])
self.assertEqual("H. Lichner", t1["artist-credit-phrase"])
self.assertNotEqual(t1["recording"]["artist-credit-phrase"], t1["artist-credit-phrase"])
def testTrackLength(self):
"""
Test that if there is a track length, then `track_or_recording_length` has
that, but if not then fill the value from the recording length
"""
fn = os.path.join(self.datadir, "b66ebe6d-a577-4af8-9a2e-a029b2147716-recordings.xml")
res = mbxml.parse_message(open(fn))
tracks = res["release"]["medium-list"][0]["track-list"]
# No track length and recording length
t1 = tracks[0]
self.assertTrue("length" not in t1)
self.assertEqual("180000", t1["recording"]["length"])
self.assertEqual("180000", t1["track_or_recording_length"])
# Track length and recording length same
t2 = tracks[1]
self.assertEqual("279000", t2["length"])
self.assertEqual("279000", t2["recording"]["length"])
self.assertEqual("279000", t2["track_or_recording_length"])
# Track length and recording length different
t3 = tracks[2]
self.assertEqual("60000", t3["length"])
self.assertEqual("80000", t3["recording"]["length"])
self.assertEqual("60000", t3["track_or_recording_length"])
# No track lengths
t4 = tracks[3]
self.assertTrue("length" not in t4["recording"])
self.assertTrue("length" not in t4)
self.assertTrue("track_or_recording_length" not in t4)
def testTrackTitle(self):
pass
def testTrackNumber(self):
"""
Test that track number (number or text) and track position (always an increasing number)
are both read properly
"""
fn = os.path.join(self.datadir, "212895ca-ee36-439a-a824-d2620cd10461-recordings.xml")
res = mbxml.parse_message(open(fn))
tracks = res["release"]["medium-list"][0]["track-list"]
# This release doesn't number intro tracks as numbered tracks,
# so position and number get 'out of sync'
self.assertEqual(['1', '2', '3'], [t["position"] for t in tracks[:3]])
self.assertEqual(['', '1', '2'], [t["number"] for t in tracks[:3]])
fn = os.path.join(self.datadir, "a81f3c15-2f36-47c7-9b0f-f684a8b0530f-recordings.xml")
res = mbxml.parse_message(open(fn))
tracks = res["release"]["medium-list"][0]["track-list"]
self.assertEqual(['1', '2'], [t["position"] for t in tracks])
self.assertEqual(['A', 'B'], [t["number"] for t in tracks])
musicbrainzngs-0.4/test/test_mbxml_work.py 0000664 0001750 0001750 00000002767 12104304065 022617 0 ustar alastair alastair 0000000 0000000 # coding=utf-8
# Tests for parsing of work queries
import unittest
import os
import sys
# Insert .. at the beginning of path so we use this version instead
# of something that's already been installed
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import musicbrainzngs
from musicbrainzngs import mbxml
class GetWorkTest(unittest.TestCase):
def setUp(self):
self.datadir = os.path.join(os.path.dirname(__file__), "data", "work")
def testWorkAliases(self):
fn = os.path.join(self.datadir, "80737426-8ef3-3a9c-a3a6-9507afb93e93-aliases.xml")
res = mbxml.parse_message(open(fn))
aliases = res["work"]["alias-list"]
self.assertEqual(len(aliases), 2)
a0 = aliases[0]
self.assertEqual(a0["alias"], 'Symphonie Nr. 3 Es-Dur, Op. 55 "Eroica"')
self.assertEqual(a0["sort-name"], 'Symphonie Nr. 3 Es-Dur, Op. 55 "Eroica"')
a1 = aliases[1]
self.assertEqual(a1["alias"], 'Symphony No. 3, Op. 55 "Eroica"')
self.assertEqual(a1["sort-name"], 'Symphony No. 3, Op. 55 "Eroica"')
fn = os.path.join(self.datadir, "3d7c7cd2-da79-37f4-98b8-ccfb1a4ac6c4-aliases.xml")
res = mbxml.parse_message(open(fn))
aliases = res["work"]["alias-list"]
self.assertEqual(len(aliases), 10)
a0 = aliases[0]
self.assertEqual(a0["alias"], "Adagio from Symphony No. 2 in E minor, Op. 27")
self.assertEqual(a0["sort-name"], "Adagio from Symphony No. 2 in E minor, Op. 27")
musicbrainzngs-0.4/test/data/ 0000775 0001750 0001750 00000000000 12144757472 017744 5 ustar alastair alastair 0000000 0000000 musicbrainzngs-0.4/test/data/label/ 0000775 0001750 0001750 00000000000 12144757472 021023 5 ustar alastair alastair 0000000 0000000 musicbrainzngs-0.4/test/data/label/e72fabf2-74a3-4444-a9a5-316296cbfc8d-aliases.xml 0000664 0001750 0001750 00000001015 12104304065 030065 0 ustar alastair alastair 0000000 0000000