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 <kimlong221002@gmail.com>
This commit is contained in:
ABCbum
2019-12-18 13:34:38 +07:00
committed by JoeLametta
parent 78c91fd1c7
commit bb66a092cd

View File

@@ -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()