def test_submit_single_tag(self): self.opener = _common.FakeOpener("<response/>") musicbrainzngs.compat.build_opener = lambda *args: self.opener def make_xml(**kwargs): self.assertEqual({'artist_tags': {'mbid': ['single']}}, kwargs) oldmake_tag_request = musicbrainz.mbxml.make_tag_request musicbrainz.mbxml.make_tag_request = make_xml musicbrainz.submit_tags(artist_tags={"mbid": "single"}) musicbrainz.mbxml.make_tag_request = oldmake_tag_request
def test_coverid(self): resp = 'some_image' self.opener = _common.FakeOpener(resp) musicbrainzngs.compat.build_opener = lambda *args: self.opener res = caa.get_image("8ec178f4-a8e8-4f22-bcba-1964466ef214", "1234") self.assertEqual( "http://coverartarchive.org/release/8ec178f4-a8e8-4f22-bcba-1964466ef214/1234", self.opener.myurl) self.assertEqual(resp, res)
def test_list_baduuid(self): exc = compat.HTTPError("", 400, "", "", _common.StringIO.StringIO("")) self.opener = _common.FakeOpener( exception=musicbrainzngs.ResponseError(cause=exc)) musicbrainzngs.compat.build_opener = lambda *args: self.opener try: res = caa.get_image_list("8ec178f4-a8e8-4f22-bcba-19644XXXXXX") self.assertTrue(False, "Expected an exception") except musicbrainzngs.ResponseError as e: self.assertEqual(e.cause.code, 400)
def test_get_list(self): # check the url and response for a listing resp = '{"images":[]}' self.opener = _common.FakeOpener(resp) musicbrainzngs.compat.build_opener = lambda *args: self.opener res = caa.get_image_list("8ec178f4-a8e8-4f22-bcba-1964466ef214") self.assertEqual( "http://coverartarchive.org/release/8ec178f4-a8e8-4f22-bcba-1964466ef214", self.opener.myurl) self.assertEqual(1, len(res)) self.assertTrue("images" in res)
def test_release_group_front(self): resp = 'front_image' self.opener = _common.FakeOpener(resp) musicbrainzngs.compat.build_opener = lambda *args: self.opener res = caa.get_release_group_image_front( "8ec178f4-a8e8-4f22-bcba-1964466ef214") self.assertEqual( "http://coverartarchive.org/release-group/8ec178f4-a8e8-4f22-bcba-1964466ef214/front", self.opener.myurl) self.assertEqual(resp, res)
def test_no_collection(self): """ If a collection doesn't exist, you get a 404 """ exc = compat.HTTPError("", 404, "", "", _common.StringIO.StringIO("")) self.opener = _common.FakeOpener(exception=musicbrainzngs.ResponseError(cause=exc)) musicbrainzngs.compat.build_opener = lambda *args: self.opener try: res = musicbrainzngs.get_releases_in_collection("17905fdb-102d-40f0-91d3-eabcabc64f44") self.assertTrue(False, "Expected an exception") except musicbrainzngs.ResponseError as e: self.assertEqual(e.cause.code, 404)
def test_private_collection(self): """ If you ask for a collection that is private, you should get a 401""" exc = compat.HTTPError("", 401, "", "", _common.StringIO.StringIO("")) self.opener = _common.FakeOpener(exception=musicbrainzngs.AuthenticationError(cause=exc)) musicbrainzngs.compat.build_opener = lambda *args: self.opener try: res = musicbrainzngs.get_releases_in_collection("17905fdb-102d-40f0-91d3-eabcabc64fd3") self.assertTrue(False, "Expected an exception") except musicbrainzngs.AuthenticationError as e: self.assertEqual(e.cause.code, 401)
def test_set_useragent(self): """ When a useragent is set it is sent with the request """ musicbrainzngs.set_useragent("caa-test", "0.1") resp = '{"images":[]}' self.opener = _common.FakeOpener(resp) musicbrainzngs.compat.build_opener = lambda *args: self.opener res = caa.get_image_list("8ec178f4-a8e8-4f22-bcba-1964466ef214") headers = dict(self.opener.headers) self.assertTrue("User-agent" in headers) self.assertEqual("caa-test/0.1 python-musicbrainzngs/%s" % _version, headers["User-agent"])
def setUp(self): self.opener = _common.FakeOpener("<response/>") musicbrainzngs.compat.build_opener = lambda *args: self.opener musicbrainzngs.set_useragent("test", "1") musicbrainzngs.set_rate_limit(False)
def setUp(self): self.opener = _common.FakeOpener("<response/>") musicbrainzngs.compat.build_opener = lambda *args: self.opener musicbrainz.auth("user", "password")
def setUp(self): self.opener = _common.FakeOpener("<response/>") musicbrainzngs.compat.build_opener = lambda *args: self.opener
def setUp(self): self.opener = _common.FakeOpener("<response/>") musicbrainzngs.compat.build_opener = lambda *args: self.opener self.orig_do_rate_limit = musicbrainz.do_rate_limit musicbrainz.do_rate_limit = False
def setUp(self): self.opener = _common.FakeOpener("<response/>") musicbrainzngs.compat.build_opener = lambda *args: self.opener.add_handlers_and_return( args) musicbrainz.set_rate_limit(False)