Tests de get_artist_of_recording
This commit is contained in:
@@ -239,6 +239,7 @@ def get_artist_of_recording(mbid):
|
|||||||
artist = redis.get(f'artist:{artist_id}')
|
artist = redis.get(f'artist:{artist_id}')
|
||||||
if not artist:
|
if not artist:
|
||||||
_log.debug('El artista aun no se carga en redis')
|
_log.debug('El artista aun no se carga en redis')
|
||||||
|
jobs.load_entities_of_recording.delay(mbid)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
_log.debug('Se encontro el artista')
|
_log.debug('Se encontro el artista')
|
||||||
|
|||||||
@@ -815,3 +815,64 @@ class CacheTest(TestCase):
|
|||||||
self.assertEquals(total, 10)
|
self.assertEquals(total, 10)
|
||||||
|
|
||||||
mock_jobs.load_entities_of_recording.delay.assert_not_called()
|
mock_jobs.load_entities_of_recording.delay.assert_not_called()
|
||||||
|
|
||||||
|
@patch('fetcher.cache.jobs')
|
||||||
|
@patch('fetcher.cache.get_redis_connection')
|
||||||
|
def test_get_artist_of_recordings_input_not_exists(self, mock_connection, mock_jobs):
|
||||||
|
"""Testear get artist of recording cuando no existe"""
|
||||||
|
mock_redis = CacheTest.mock_redis(mock_connection)
|
||||||
|
|
||||||
|
def get(key):
|
||||||
|
if key == 'recording:mbid:artist':
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
self.fail(f'Key inesperada en get: {key}')
|
||||||
|
|
||||||
|
mock_redis.get = get
|
||||||
|
|
||||||
|
result = cache.get_artist_of_recording('mbid')
|
||||||
|
self.assertEquals(result, None)
|
||||||
|
|
||||||
|
mock_jobs.load_entities_of_recording.delay.assert_called_with('mbid')
|
||||||
|
|
||||||
|
@patch('fetcher.cache.jobs')
|
||||||
|
@patch('fetcher.cache.get_redis_connection')
|
||||||
|
def test_get_artist_of_recordings_not_loaded(self, mock_connection, mock_jobs):
|
||||||
|
"""Testear get artist of recording cuando existe id pero no esta cargado"""
|
||||||
|
mock_redis = CacheTest.mock_redis(mock_connection)
|
||||||
|
|
||||||
|
def get(key):
|
||||||
|
if key == 'recording:mbid:artist':
|
||||||
|
return 'artist_id'
|
||||||
|
elif key == 'artist:artist_id':
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
self.fail(f'Key inesperada en get: {key}')
|
||||||
|
|
||||||
|
mock_redis.get = get
|
||||||
|
|
||||||
|
result = cache.get_artist_of_recording('mbid')
|
||||||
|
self.assertEquals(result, None)
|
||||||
|
|
||||||
|
mock_jobs.load_entities_of_recording.delay.assert_called_with('mbid')
|
||||||
|
|
||||||
|
@patch('fetcher.cache.jobs')
|
||||||
|
@patch('fetcher.cache.get_redis_connection')
|
||||||
|
def test_get_artist_of_recordings_exists(self, mock_connection, mock_jobs):
|
||||||
|
"""Testear get artist of recording cuando existe"""
|
||||||
|
mock_redis = CacheTest.mock_redis(mock_connection)
|
||||||
|
|
||||||
|
def get(key):
|
||||||
|
if key == 'recording:mbid:artist':
|
||||||
|
return 'artist_id'
|
||||||
|
elif key == 'artist:artist_id':
|
||||||
|
return json.dumps({'id': 'artist_id'})
|
||||||
|
else:
|
||||||
|
self.fail(f'Key inesperada en get: {key}')
|
||||||
|
|
||||||
|
mock_redis.get = get
|
||||||
|
|
||||||
|
result = cache.get_artist_of_recording('mbid')
|
||||||
|
self.assertEquals(result, {'id': 'artist_id'})
|
||||||
|
|
||||||
|
mock_jobs.load_entities_of_recording.delay.assert_not_called()
|
||||||
|
|||||||
Reference in New Issue
Block a user