From bb66a092cd586546ecf12159ba1375f6945ce3a6 Mon Sep 17 00:00:00 2001 From: ABCbum Date: Wed, 18 Dec 2019 13:34:38 +0700 Subject: [PATCH] Add test case to new mblookup functionality A new test case to check for mblookup's ability to search for data based on release id is created along with a function mocks getReleaseMetadata using an existing JSON file. Signed-off-by: ABCbum --- whipper/test/test_command_mblookup.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/whipper/test/test_command_mblookup.py b/whipper/test/test_command_mblookup.py index c13cb93..39d058a 100644 --- a/whipper/test/test_command_mblookup.py +++ b/whipper/test/test_command_mblookup.py @@ -4,8 +4,10 @@ import os import pickle import unittest +import json from whipper.command import mblookup +from whipper.common.mbngs import _getMetadata class MBLookupTestCase(unittest.TestCase): @@ -19,6 +21,22 @@ class MBLookupTestCase(unittest.TestCase): with open(path, "rb") as p: return pickle.load(p) + @staticmethod + def _mock_getReleaseMetadata(release_id): + """ + Mock function for whipper.common.mbngs.getReleaseMetadata. + + :param release_id: MusicBrainz Release ID + :type release_id: str + :returns: a DiscMetadata object based on the given release_id + :rtype: `DiscMetadata` + """ + filename = 'whipper.release.{}.json'.format(release_id) + path = os.path.join(os.path.dirname(__file__), filename) + with open(path, "rb") as handle: + response = json.loads(handle.read().decode('utf-8')) + return _getMetadata(response['release']) + def testMissingReleaseType(self): """Test that lookup for release without a type set doesn't fail.""" # Using: Gustafsson, Österberg & Cowle - What's Up? 8 (disc 4) @@ -28,3 +46,12 @@ class MBLookupTestCase(unittest.TestCase): # https://musicbrainz.org/cdtoc/xu338_M8WukSRi0J.KTlDoflB8Y- lookup = mblookup.MBLookup([discid], 'whipper mblookup', None) lookup.do() + + def testGetDataFromReleaseId(self): + """Test that lookup for a release with a specified id.""" + # Using: The KLF - Space & Chill Out + # https://musicbrainz.org/release/c56ff16e-1d81-47de-926f-ba22891bd2bd + mblookup.getReleaseMetadata = self._mock_getReleaseMetadata + releaseid = 'c56ff16e-1d81-47de-926f-ba22891bd2bd' + lookup = mblookup.MBLookup([releaseid], 'whipper mblookup', None) + lookup.do()