def test03_get_available_games(self): c = self.db.cursor() owner_id = 42 # Define some datetimes. now = datetime.now() an_hour_ago = now - timedelta(hours=1) yesterday = now - timedelta(days=1) two_days_ago = now - timedelta(days=2) three_days_ago = now - timedelta(days=3) sec = timedelta(seconds=1) # Create some games. sql = 'INSERT INTO games (id, owner_id, state, sentence, created) VALUES (?, ?, ?, ?, ?)' games = [ [1, 'invitation', 'Story 1', three_days_ago], [2, 'invitation', 'Story 2', two_days_ago], [3, 'create', '', yesterday], [4, 'voting', 'Story 4', yesterday], [5, 'canceled', 'Story 5', an_hour_ago], [6, 'complete', 'Story 6', an_hour_ago], [7, 'invitation', 'Story 7', now], ] for game in games: c.execute(sql, [game[0], owner_id, game[1], game[2], game[3]]) # Seed the playerid2name data. aggregate.seed_playerid2name([(owner_id, '*****@*****.**', 'John Johnson', False)]) # Fetching all available games since two days ago should yeild two results. result = aggregate.get_available_games(c, two_days_ago - sec) self.assertEquals(len(result), 2) self.assertEquals(result[0]['game_id'], 2) self.assertEquals(result[0]['owner_name'], 'John Johnson') self.assertEquals(result[0]['sentence'], 'Story 2') self.assertEquals(result[1]['game_id'], 7) self.assertEquals(result[1]['owner_name'], 'John Johnson') self.assertEquals(result[1]['sentence'], 'Story 7') # Fetching all available games since three days ago should yeild three results, # but we are excluding three of them with the third optional parameter, # so there should be only one game in the result. result = aggregate.get_available_games(c, three_days_ago - sec, [2, 7, 888]) self.assertEquals(len(result), 1) self.assertEquals(result[0]['game_id'], 1) self.assertEquals(result[0]['owner_name'], 'John Johnson') self.assertEquals(result[0]['sentence'], 'Story 1')
def test03_get_available_games(self): c = self.db.cursor() owner_id = 42 # Define some datetimes. now = datetime.now() an_hour_ago = now - timedelta(hours=1) yesterday = now - timedelta(days=1) two_days_ago = now - timedelta(days=2) three_days_ago = now - timedelta(days=3) sec = timedelta(seconds=1) # Create some games. sql = 'INSERT INTO games (id, owner_id, state, sentence, created) VALUES (?, ?, ?, ?, ?)' games = [ [1, 'invitation', 'Story 1', three_days_ago], [2, 'invitation', 'Story 2', two_days_ago], [3, 'create', '', yesterday], [4, 'voting', 'Story 4', yesterday], [5, 'canceled', 'Story 5', an_hour_ago], [6, 'complete', 'Story 6', an_hour_ago], [7, 'invitation', 'Story 7', now], ] for game in games: c.execute(sql, [game[0], owner_id, game[1], game[2], game[3]]) # Seed the playerid2name data. aggregate.seed_playerid2name([(owner_id, '*****@*****.**', 'John Johnson')]) # Fetching all available games since two days ago should yeild two results. result = aggregate.get_available_games(c, two_days_ago - sec) self.assertEquals(len(result), 2) self.assertEquals(result[0]['game_id'], 2) self.assertEquals(result[0]['owner_name'], 'John Johnson') self.assertEquals(result[0]['sentence'], 'Story 2') self.assertEquals(result[1]['game_id'], 7) self.assertEquals(result[1]['owner_name'], 'John Johnson') self.assertEquals(result[1]['sentence'], 'Story 7') # Fetching all available games since three days ago should yeild three results, # but we are excluding three of them with the third optional parameter, # so there should be only one game in the result. result = aggregate.get_available_games(c, three_days_ago - sec, [2, 7, 888]) self.assertEquals(len(result), 1) self.assertEquals(result[0]['game_id'], 1) self.assertEquals(result[0]['owner_name'], 'John Johnson') self.assertEquals(result[0]['sentence'], 'Story 1')
def get_context(cursor, player_id, last_active): game_ids = aggregate.get_player_game_ids(cursor, player_id) game_activities = aggregate.get_game_activities(cursor, game_ids, player_id, happened_since=last_active) available_games = aggregate.get_available_games(cursor, created_since=last_active, exclude_game_ids=game_ids) completed_games = aggregate.get_completed_games(cursor, completed_since=last_active, exclude_game_ids=game_ids) context = {'game_activities': game_activities, 'available_games': available_games, 'completed_games': completed_games} return context
def get_context(cursor, player_id, game_ids, last_active): game_activities = aggregate.get_game_activities(cursor, game_ids, player_id, happened_since=last_active) available_games = aggregate.get_available_games(cursor, created_since=last_active, exclude_game_ids=game_ids) completed_games = aggregate.get_completed_games(cursor, completed_since=last_active, exclude_game_ids=game_ids) unsubscribe_path = reverse(website.cardstories.views.activity_notifications_unsubscribe) context = {'game_activities': game_activities, 'available_games': available_games, 'completed_games': completed_games, 'unsubscribe_path': unsubscribe_path} return context
def get_context(cursor, player_id, game_ids, last_active): game_activities = aggregate.get_game_activities(cursor, game_ids, player_id, happened_since=last_active) available_games = aggregate.get_available_games(cursor, created_since=last_active, exclude_game_ids=game_ids) completed_games = aggregate.get_completed_games( cursor, completed_since=last_active, exclude_game_ids=game_ids) unsubscribe_path = reverse( website.cardstories.views.activity_notifications_unsubscribe) context = { 'game_activities': game_activities, 'available_games': available_games, 'completed_games': completed_games, 'unsubscribe_path': unsubscribe_path } return context