def test_get_friends_for__only_candidates(self): FriendshipPrototype.request_friendship(self.account_1, self.account_2, 'text 1') FriendshipPrototype.request_friendship(self.account_3, self.account_1, 'text 2') self.assertEqual(FriendshipPrototype.get_friends_for(self.account_1), [])
def test_get_friends_for__friends_exists(self): FriendshipPrototype.request_friendship(self.account_1, self.account_2, 'text 1')._confirm() FriendshipPrototype.request_friendship(self.account_3, self.account_1, 'text 2')._confirm() self.assertEqual( set(account.id for account in FriendshipPrototype.get_friends_for( self.account_1)), set([self.account_2.id, self.account_3.id]))
def friends(self): friends = FriendshipPrototype.get_friends_for(self.account) candidates = FriendshipPrototype.get_candidates_for(self.account) accounts_ids = [account.id for account in friends] clans_ids = [model.clan_id for model in friends] heroes = {hero.account_id: hero for hero in heroes_logic.load_heroes_by_account_ids(accounts_ids)} clans = {clan.id: clan for clan in ClanPrototype.get_list_by_id(clans_ids)} return self.template( "friends/friends_list.html", {"friends": friends, "candidates": candidates, "heroes": heroes, "clans": clans}, )
def friends(self): friends = FriendshipPrototype.get_friends_for(self.account) candidates = FriendshipPrototype.get_candidates_for(self.account) accounts_ids = [account.id for account in friends] clans_ids = [ model.clan_id for model in friends] heroes = dict( (model.account_id, HeroPrototype(model=model)) for model in Hero.objects.filter(account_id__in=accounts_ids)) clans = {clan.id:clan for clan in ClanPrototype.get_list_by_id(clans_ids)} return self.template('friends/friends_list.html', {'friends': friends, 'candidates': candidates, 'heroes': heroes, 'clans': clans})
def friends(self): friends = FriendshipPrototype.get_friends_for(self.account) candidates = FriendshipPrototype.get_candidates_for(self.account) accounts_ids = [account.id for account in friends] clans_ids = [model.clan_id for model in friends] heroes = dict( (model.account_id, HeroPrototype(model=model)) for model in Hero.objects.filter(account_id__in=accounts_ids)) clans = { clan.id: clan for clan in ClanPrototype.get_list_by_id(clans_ids) } return self.template( 'friends/friends_list.html', { 'friends': friends, 'candidates': candidates, 'heroes': heroes, 'clans': clans })
def friends(self): friends = FriendshipPrototype.get_friends_for(self.account) candidates = FriendshipPrototype.get_candidates_for(self.account) accounts_ids = [account.id for account in friends] clans_ids = [model.clan_id for model in friends] heroes = { hero.account_id: hero for hero in heroes_logic.load_heroes_by_account_ids(accounts_ids) } clans = { clan.id: clan for clan in ClanPrototype.get_list_by_id(clans_ids) } return self.template( 'friends/friends_list.html', { 'friends': friends, 'candidates': candidates, 'heroes': heroes, 'clans': clans })
def test_get_friends_for__no_friendship(self): self.assertEqual(FriendshipPrototype.get_friends_for(self.account_1), [])
def test_get_friends_for__friends_exists(self): FriendshipPrototype.request_friendship(self.account_1, self.account_2, 'text 1')._confirm() FriendshipPrototype.request_friendship(self.account_3, self.account_1, 'text 2')._confirm() self.assertEqual(set(account.id for account in FriendshipPrototype.get_friends_for(self.account_1)), set([self.account_2.id, self.account_3.id]))
def test_get_friends_for__only_candidates(self): FriendshipPrototype.request_friendship(self.account_1, self.account_2, 'text 1') FriendshipPrototype.request_friendship(self.account_3, self.account_1, 'text 2') self.assertEqual(FriendshipPrototype.get_friends_for(self.account_1), [])
def test_get_friends_for__no_friendship(self): self.assertEqual(FriendshipPrototype.get_friends_for(self.account_1), [])