def test_check_last_period(self): self.assertEqual( checkdb.check_last_period('69lmao'), None ) self.assertEqual( checkdb.check_last_period('440'), None ) self.assertEqual( checkdb.check_last_period('1488'), None ) self.assertEqual( checkdb.check_last_period('101'), ('101',100,25) ) self.assertEqual( checkdb.check_last_period('202'), ('202',100,10) ) self.assertEqual( checkdb.check_last_period('303'), ('303',150,25) ) for id_ in self.ids: case=getterdb.steam_game_getter(id_,logger) logger.debug( """ {} last_checked: {} """.format(id_,case.last_checked))
def test_main(self): ###Documentation """ Creates a mock achievements document and simulates the main function of steam_setters_achievements. Checks if the mock document has been reseted and if all data has been pushed into the db """ ###Creating mock achievements document with open('achievements.json', 'w') as mockdoc: mockdict = {'games': {'69lmao': {'bruh': 80.3, 'brah': 1.0}}} json.dump(mockdict, mockdoc, indent=2) ###Appliying main module function for mock document CURRENT_DIR = os.getcwd() a_dict = mainmodule.get_achievements(CURRENT_DIR) mainmodule.push_achievements(a_dict) ###Checking mock document reset with open('achievements.json', 'r') as mockdoc: a_dict = json.load(mockdoc) self.assertEqual(a_dict, {'games': {}}) ###Checking database steamgame = getterdb.steam_game_getter('69lmao', logger) D_4 = dt.date.today() final_result = { 'bruh': [(self.D_1, 0.1), (self.D_2, 80.3), (self.D_3, 1.2), (D_4, 80.3)], 'get_big_td_goth_gf': [(self.D_1, 0.0), (self.D_2, 0.0), (self.D_3, 0.0)], 'give_up_on_life': [(self.D_1, 100.0), (self.D_2, 100.0), (self.D_3, 100.0)], 'brah': [(D_4, 1.0)] } for a in steamgame.achievements: if a.achievement_id == 'bruh': percents = a.percentages percents = [(p[0].date(), p[1]) for p in percents] self.assertEqual(percents, final_result['bruh']) elif a.achievement_id == 'brah': percents = a.percentages percents = [(percents[0][0].date(), percents[0][1])] self.assertEqual(percents, final_result['brah'])
def push_achievements(a_dict: dict) -> None: ##Documentation """ Pushes the content for every game registered in a_dict to SteamDB using the function steam_achievement_setter from steam_setters_db Parameters ---------- a_dict: dict Contains all appids of standby games as keys, the achievements data is registered in the values as nested dictionaries with the achievement ids as keys and the percerntages as values. """ ##Pushing items into db for item in a_dict.items(): appid, app_json = item steamgame = getterdb.steam_game_getter(appid, logger) steamgame = setterdb.steam_achievement_setter(steamgame, app_json, logger) setterdb.steam_game_save(steamgame)
def test_steam_achievement_setter(self): ###Documentation """ Assigns to fake game new achievements, tests function's response to old, missing and new achievements. Asserts that all the information is correctly stored in db. You must manually check if the loggers write the correct messages. """ ###Setting new achievements steamgame = self.game new_achievements = { 'bruh': 50.8, 'give_up_on_life': 100, 'get_diagnosed_with_the_gay': 50.0 } steamgame = setterdb.steam_achievement_setter(steamgame, new_achievements, logger) setterdb.steam_game_save(steamgame) ###This is how the results are supposed to be D_4 = dt.date.today() final_result = { 'bruh': [(self.D_1, 0.1), (self.D_2, 80.3), (self.D_3, 1.2), (D_4, 50.8)], 'give_up_on_life': [(self.D_1, 100.0), (self.D_2, 100.0), (self.D_3, 100.0), (D_4, 100.0)], 'get_big_td_goth_gf': [(self.D_1, 0.0), (self.D_2, 0.0), (self.D_3, 0.0)], 'get_diagnosed_with_the_gay': [(D_4, 50.0)] } ###Checking database steamgame = getterdb.steam_game_getter('69lmao', logger) achievements = steamgame.achievements for a in achievements: a.percentages = [(p[0].date(), p[1]) for p in a.percentages] print(a.achievement_id) self.assertEqual(final_result[a.achievement_id], a.percentages)
def setUpClass(cls): ###Documentation """ Creates a fake SteamGame and sets some fictional achievement vectors. """ ###Conecting to db and creating game connectdb.register_connection('SteamDB', 'SteamDB') setterdb.steam_game_setter('69lmao', logger) steamgame = getterdb.steam_game_getter('69lmao', logger) ###Dates for achievements vector D_1 = dt.datetime(2019, 1, 1) D_2 = dt.datetime(2019, 1, 2) D_3 = dt.datetime(2019, 1, 3) ###Achievements vectors old_achievements = { 'bruh': [(D_1, 0.1), (D_2, 80.3), (D_3, 1.2)], 'get_big_td_goth_gf': [(D_1, 0.0), (D_2, 0.0), (D_3, 0.0)], 'give_up_on_life': [(D_1, 100.0), (D_2, 100.0), (D_3, 100.0)] } cls.D_1 = D_1.date() cls.D_2 = D_2.date() cls.D_3 = D_3.date() ###Introducing achievement vectors into object for tuple_ in old_achievements.items(): achievement_instance = gamedb.AchievementRegister() achievement_instance.achievement_id = tuple_[0] achievement_instance.percentages.extend(tuple_[1]) steamgame.achievements.append(achievement_instance) ###Saving object cls.game = steamgame setterdb.steam_game_save(steamgame)
def setUpClass(cls): ###Connecting to db and creating mock SteamGame objects connectdb.register_connection('SteamDB','SteamDB') id_ls=[ '69lmao','440','1488', '101','202','303' ] cls.ids=id_ls [setterdb.steam_game_setter(id_,logger) for id_ in id_ls] ###Posible cases ####Current state is not i case_1=getterdb.steam_game_getter('69lmao',logger) case_1=setterdb.steam_game_timeperiod_setter( case_1, '69lmao_0', 'al', dt.date(2019,5,14), dt.date(2019,6,14), logger ) case_1=setterdb.steam_game_timeperiod_setter( case_1, '69lmao_1', 's', dt.date(2019,6,15), dt.date(2019,7,15), logger ) case_1=setterdb.steam_game_timeperiod_setter( case_1, '69lmao_2', 'i', dt.date(2019,7,16), dt.date(2019,8,15), logger ) case_1.current_state='as' case_1.last_checked=dt.date(2020,1,1) setterdb.steam_game_save(case_1) cls.case_1=case_1 ####Current state is i but no s periods case_2=getterdb.steam_game_getter('440',logger) case_2=setterdb.steam_game_timeperiod_setter( case_2, '440_0', 'al', dt.date(2019,5,14), dt.date(2019,6,14), logger ) case_2=setterdb.steam_game_timeperiod_setter( case_2, '440_1', 'as', dt.date(2019,5,14), dt.date(2019,6,14), logger ) case_2.current_state='i' case_2.last_checked=dt.date(2020,1,1) setterdb.steam_game_save(case_2) cls.case_2=case_2 ####Current state is i but last period was not s case_3=getterdb.steam_game_getter('1488',logger) case_3=setterdb.steam_game_timeperiod_setter( case_3, '1488_0', 'al', dt.date(2019,5,14), dt.date(2019,6,14), logger ) case_3=setterdb.steam_game_timeperiod_setter( case_3, '1488_1', 's', dt.date(2019,5,14), dt.date(2019,6,14), logger ) case_3.current_state='i' case_3.last_checked=dt.date(2020,1,1) setterdb.steam_game_save(case_3) cls.case_3=case_3 ####Current state is i and last period was s (various games) case_4_0=getterdb.steam_game_getter('101',logger) case_4_0=setterdb.steam_game_timeperiod_setter( case_4_0, '101_0', 'al', dt.date(2019,5,14), dt.date(2019,6,14), logger ) case_4_0=setterdb.steam_game_timeperiod_setter( case_4_0, '101_1', 's', dt.date(2019,6,14), dt.date(2019,7,14), logger, av=100, dev=25 ) case_4_0.current_state='i' case_4_0.last_checked=dt.date(2020,1,1) setterdb.steam_game_save(case_4_0) cls.case_4_0=case_4_0 case_4_1=getterdb.steam_game_getter('202',logger) case_4_1=setterdb.steam_game_timeperiod_setter( case_4_1, '202_0', 'al', dt.date(2019,5,14), dt.date(2019,6,14), logger ) case_4_1=setterdb.steam_game_timeperiod_setter( case_4_1, '202_1', 's', dt.date(2019,6,14), dt.date(2019,7,14), logger, av=200, dev=100 ) case_4_1=setterdb.steam_game_timeperiod_setter( case_4_1, '202_2', 'as', dt.date(2019,7,15), dt.date(2019,8,14), logger ) case_4_1=setterdb.steam_game_timeperiod_setter( case_4_1, '202_3', 's', dt.date(2019,8,15), dt.date(2019,9,14), logger, av=100, dev=10 ) case_4_1.current_state='i' case_4_1.last_checked=dt.date(2020,1,4) setterdb.steam_game_save(case_4_1) cls.case_4_1=case_4_1 case_4_2=getterdb.steam_game_getter('303',logger) case_4_2=setterdb.steam_game_timeperiod_setter( case_4_2, '303_0', 'al', dt.date(2019,5,14), dt.date(2019,6,14), logger ) case_4_2=setterdb.steam_game_timeperiod_setter( case_4_2, '303_1', 's', dt.date(2019,6,14), dt.date(2019,7,14), logger, av=150, dev=25 ) case_4_2.current_state='i' case_4_2.last_checked=dt.date(2020,1,5) setterdb.steam_game_save(case_4_2) cls.case_4_2=case_4_2
def main(): ##Documentation """ Module's main funciton, searches all games which prices/players tables have been downloaded, gets their appids and ratings and searches for their price/players timetables within a diretory. Modifies the csv format of the timetables into the standard format for SteamDB and sets each game attributes with the results. """ ##Connecting to db connectdb.register_connection('SteamDB','SteamDB') ##Steam db scraper dirs DOWNLOAD_PATH='../../../Scrapers/ScraperDB' PRICE_PATH='./Prices' PLAYER_PATH='./Players' ##Getting ratings os.chdir(DOWNLOAD_PATH) ratings=get_ratings(DOWNLOAD_PATH,'downloaded.csv') ##Getting price/players timetables and modifying steamgame for appid in ratings.keys(): ###Getting steamgame steamgame=getterdb.steam_game_getter(appid,logger) ###Searching, getting and setting price timetable price_doc=find_pattern(PRICE_PATH,appid,price_pattern) if price_doc: timetable=get_timetable(price_doc) steamgame=setterdb.steam_game_timeseries_setter( steamgame, timetable, 'prices', logger) os.chdir('../') ###Searching, getting and setting players timetable player_doc=find_pattern(PLAYER_PATH,appid,player_pattern) if player_doc: timetable=get_timetable(player_doc) steamgame=setterdb.steam_game_timeseries_setter( steamgame, timetable, 'players', logger) else: logger.warning('{} has not players timetable'.format(appid)) os.chdir('../') ###Setting game ratings timeseries=( dt.datetime.now(), ratings[appid][0], ratings[appid][1] ) steamgame.ratings.append(timeseries) ###Saving game in db setterdb.steam_game_save(steamgame)
def test_main(self): ttsetter.main() steamgame=getterdb.steam_game_getter('69',logger).to_json() logger.debug('Game db: {}'.format(steamgame))