Tests de get_artist_of_recording

This commit is contained in:
Daniel Cortes
2020-06-14 04:04:16 -04:00
parent 907cfe92d5
commit 71fe9523a9
2 changed files with 62 additions and 0 deletions

View File

@@ -815,3 +815,64 @@ class CacheTest(TestCase):
self.assertEquals(total, 10)
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()