Test para get_artist_of_release
This commit is contained in:
@@ -132,6 +132,7 @@ def get_artist_of_release(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_release.delay(mbid)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
_log.debug('Se encontro el artista')
|
_log.debug('Se encontro el artista')
|
||||||
|
|||||||
@@ -300,3 +300,63 @@ class CacheTest(TestCase):
|
|||||||
mock_redis.zrange.assert_called_with('release_group:mbid:releases', 0, 10)
|
mock_redis.zrange.assert_called_with('release_group:mbid:releases', 0, 10)
|
||||||
mock_redis.exists.assert_called_with(*[f'release:{id}' for id in range(10)])
|
mock_redis.exists.assert_called_with(*[f'release:{id}' for id in range(10)])
|
||||||
mock_jobs.load_entities_of_release_group.delay.assert_not_called()
|
mock_jobs.load_entities_of_release_group.delay.assert_not_called()
|
||||||
|
|
||||||
|
@patch('fetcher.cache.jobs')
|
||||||
|
@patch('fetcher.cache.get_redis_connection')
|
||||||
|
def test_get_artist_of_release_input_no_exists(self, mock_connection, mock_jobs):
|
||||||
|
"""Testear get artist of release cuando no existe"""
|
||||||
|
|
||||||
|
mock_redis = CacheTest.mock_redis(mock_connection)
|
||||||
|
mock_redis.get = Mock(return_value=None)
|
||||||
|
|
||||||
|
result = cache.get_artist_of_release('mbid')
|
||||||
|
self.assertEquals(result, None)
|
||||||
|
|
||||||
|
mock_redis.get.assert_called_with('release:mbid:artist')
|
||||||
|
mock_jobs.load_entities_of_release.delay.assert_called_with('mbid')
|
||||||
|
|
||||||
|
@patch('fetcher.cache.jobs')
|
||||||
|
@patch('fetcher.cache.get_redis_connection')
|
||||||
|
def test_get_artist_of_release_input_not_saved(self, mock_connection, mock_jobs):
|
||||||
|
"""Testear get artist of release cuando existe el id por aun no es guardado"""
|
||||||
|
|
||||||
|
mock_redis = CacheTest.mock_redis(mock_connection)
|
||||||
|
|
||||||
|
def get(key):
|
||||||
|
if key == 'release:mbid:artist':
|
||||||
|
return 'artist_id'
|
||||||
|
if key == 'artist:artist_id':
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
self.fail('Key inesperada')
|
||||||
|
|
||||||
|
mock_redis.get = get
|
||||||
|
|
||||||
|
result = cache.get_artist_of_release('mbid')
|
||||||
|
self.assertEquals(result, None)
|
||||||
|
|
||||||
|
mock_jobs.load_entities_of_release.delay.assert_called_with('mbid')
|
||||||
|
|
||||||
|
@patch('fetcher.cache.jobs')
|
||||||
|
@patch('fetcher.cache.get_redis_connection')
|
||||||
|
def test_get_artist_of_release_exists(self, mock_connection, mock_jobs):
|
||||||
|
"""Testear get artist of release cuando existe"""
|
||||||
|
|
||||||
|
payload = {'id': 'artist_id', 'name': 'ohno'}
|
||||||
|
|
||||||
|
mock_redis = CacheTest.mock_redis(mock_connection)
|
||||||
|
|
||||||
|
def get(key):
|
||||||
|
if key == 'release:mbid:artist':
|
||||||
|
return 'artist_id'
|
||||||
|
if key == 'artist:artist_id':
|
||||||
|
return json.dumps(payload)
|
||||||
|
else:
|
||||||
|
self.fail('Key inesperada')
|
||||||
|
|
||||||
|
mock_redis.get = get
|
||||||
|
|
||||||
|
result = cache.get_artist_of_release('mbid')
|
||||||
|
self.assertEquals(result, payload)
|
||||||
|
|
||||||
|
mock_jobs.load_entities_of_release.delay.assert_not_called()
|
||||||
|
|||||||
Reference in New Issue
Block a user