Test para get_artist_of_release
This commit is contained in:
@@ -300,3 +300,63 @@ class CacheTest(TestCase):
|
||||
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_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