def test_insert_user_stats(self): with open(self.path_to_data_file('user_top_artists.json')) as f: artists = json.load(f) with open(self.path_to_data_file('user_top_releases.json')) as f: releases = json.load(f) with open(self.path_to_data_file('user_top_recordings.json')) as f: recordings = json.load(f) db_stats.insert_user_stats( user_id=self.user['id'], artists=artists, recordings=recordings, releases=releases, artist_count=2, ) result = db_stats.get_all_user_stats(user_id=self.user['id']) self.assertListEqual(result['artist']['all_time']['artists'], artists) self.assertEqual(result['artist']['count'], 2) self.assertListEqual(result['release']['all_time']['releases'], releases) self.assertListEqual(result['recording']['all_time']['recordings'], recordings) self.assertGreater(int(result['last_updated'].strftime('%s')), 0)
def test_get_all_user_stats(self): data_inserted = self.insert_test_data() result = db_stats.get_all_user_stats(self.user['id']) self.assertListEqual(result['artist']['all_time']['artists'], data_inserted['user_artists']) self.assertEqual(result['artist']['count'], 2) self.assertListEqual(result['release']['all_time']['releases'], data_inserted['user_releases']) self.assertListEqual(result['recording']['all_time']['recordings'], data_inserted['user_recordings']) self.assertGreater(int(result['last_updated'].strftime('%s')), 0)
def test_get_all_user_stats(self): data_inserted = self.insert_test_data() result = db_stats.get_all_user_stats(self.user['id']) self.assertListEqual(result['artist']['all_time'], data_inserted['user_artists']) self.assertEqual(result['artist']['count'], 2) self.assertListEqual(result['release']['all_time'], data_inserted['user_releases']) self.assertListEqual(result['recording']['all_time'], data_inserted['user_recordings']) self.assertGreater(int(result['last_updated'].strftime('%s')), 0)
def test_delete(self): user_id = db_user.create(10, 'frank') user = db_user.get(user_id) self.assertIsNotNone(user) db_stats.insert_user_stats( user_id=user_id, artists={}, recordings={}, releases={}, artist_count=2, ) user_stats = db_stats.get_all_user_stats(user_id) self.assertIsNotNone(user_stats) db_user.delete(user_id) user = db_user.get(user_id) self.assertIsNone(user) user_stats = db_stats.get_all_user_stats(user_id) self.assertIsNone(user_stats)
def test_calculate_stats_for_user(self, mock_current_app, get_top_recordings, get_top_artists, get_top_releases, get_artist_count): # invalid user data self.assertFalse(self.sc.calculate_stats_for_user({})) # now for a valid user user = { 'id': self.user['id'], 'musicbrainz_id': self.user['musicbrainz_id'], } self.assertTrue(self.sc.calculate_stats_for_user(user)) data = db_stats.get_all_user_stats(self.user['id']) self.assertIsNotNone(data) self.assertEqual(data['artist']['count'], 1) # now that we've inserted valid data and 7 days haven't passed, # calling the function should return false self.assertFalse(self.sc.calculate_stats_for_user(user))
def test_insert_user_stats(self): with open(self.path_to_data_file('user_top_artists.json')) as f: artists = json.load(f) with open(self.path_to_data_file('user_top_releases.json')) as f: releases = json.load(f) with open(self.path_to_data_file('user_top_recordings.json')) as f: recordings = json.load(f) db_stats.insert_user_stats( user_id=self.user['id'], artists=artists, recordings=recordings, releases=releases, artist_count=2, ) result = db_stats.get_all_user_stats(user_id=self.user['id']) self.assertListEqual(result['artist']['all_time'], artists) self.assertEqual(result['artist']['count'], 2) self.assertListEqual(result['release']['all_time'], releases) self.assertListEqual(result['recording']['all_time'], recordings) self.assertGreater(int(result['last_updated'].strftime('%s')), 0)