def test_register_accounts_on_initialization__multiple_accounts_bandles(self): account_3 = self.accounts_factory.create_account() account_4 = self.accounts_factory.create_account() account_5 = self.accounts_factory.create_account() account_6 = self.accounts_factory.create_account() hero_2 = HeroPrototype.get_by_account_id(self.account_2.id) hero_3 = HeroPrototype.get_by_account_id(account_3.id) hero_4 = HeroPrototype.get_by_account_id(account_4.id) hero_6 = HeroPrototype.get_by_account_id(account_6.id) hero_3.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id hero_3.actions.updated = True hero_3.save() hero_4.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id hero_4.actions.updated = True hero_4.save() hero_6.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id hero_6.actions.updated = True hero_6.save() self.worker.process_initialize() self.assertEqual(self.worker.accounts_owners, {self.account_1.id: 'game_logic_1', self.account_2.id: 'game_logic_2', account_3.id: 'game_logic_2', account_4.id: 'game_logic_2', account_5.id: 'game_logic_1', account_6.id: 'game_logic_2'}) self.assertEqual(self.worker.logic_accounts_number, {'game_logic_1': 2, 'game_logic_2': 4})
def setUp(self): super(PrototypeTests, self).setUp() current_time = TimePrototype.get_current_time() current_time.increment_turn() self.persons_changed_at_turn = TimePrototype.get_current_turn_number() self.p1, self.p2, self.p3 = create_test_map() self.person = create_person(self.p1, PERSON_STATE.IN_GAME) result, account_id, bundle_id = register_user('test_user1', '*****@*****.**', '111111') self.hero_1 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user2', '*****@*****.**', '111111') self.hero_2 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user3', '*****@*****.**', '111111') self.hero_3 = HeroPrototype.get_by_account_id(account_id) current_time = TimePrototype.get_current_time() current_time.increment_turn()
def test_game_info_data_hidding(self): ''' player hero always must show actual data enemy hero always must show data on statrt of the turn ''' self.pvp_create_battle(self.account_1, self.account_2, BATTLE_1X1_STATE.PROCESSING) self.pvp_create_battle(self.account_2, self.account_1, BATTLE_1X1_STATE.PROCESSING) hero_1 = HeroPrototype.get_by_account_id(self.account_1.id) hero_2 = HeroPrototype.get_by_account_id(self.account_2.id) hero_1.pvp.set_energy(1) hero_1.save() hero_2.pvp.set_energy(2) hero_2.save() data = form_game_info(self.account_1, is_own=True) self.assertEqual(data['account']['hero']['pvp']['energy'], 1) self.assertEqual(data['enemy']['hero']['pvp']['energy'], 0) hero_2.pvp.store_turn_data() hero_2.save() data = form_game_info(self.account_1, is_own=True) self.assertEqual(data['enemy']['hero']['pvp']['energy'], 2)
def check_heroes(self): result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') hero_1 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') hero_2 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111') hero_3 = HeroPrototype.get_by_account_id(account_id) hero_1.premium_state_end_at = datetime.datetime.now() + datetime.timedelta(seconds=60) hero_1.preferences.set_place(self.place_1) hero_1.preferences.set_friend(self.place_1.persons[0]) hero_1.preferences.set_enemy(self.place_1.persons[-1]) hero_1.save() hero_2.premium_state_end_at = datetime.datetime.now() + datetime.timedelta(seconds=60) hero_2.preferences.set_place(self.place_1) hero_2.preferences.set_friend(self.place_1.persons[-1]) hero_2.preferences.set_enemy(self.place_1.persons[0]) hero_2.save() hero_3.preferences.set_place(self.place_1) hero_3.preferences.set_friend(self.place_1.persons[-1]) hero_3.preferences.set_enemy(self.place_1.persons[0]) hero_3.save() texts = [(jinja2.escape(hero_1.name), 3), (jinja2.escape(hero_2.name), 3), (jinja2.escape(hero_3.name), 0)] self.check_html_ok(self.request_html(url('game:map:places:show', self.place_1.id)), texts=texts)
def test_remove_game_data(self): self.assertEqual(HeroPrototype._db_count(), 1) remove_game_data(AccountPrototype.get_by_id(self.account_id)) self.assertEqual(HeroPrototype._db_count(), 0)
def get_achievements_source_iterator(self, achievement): from the_tale.accounts.prototypes import AccountPrototype from the_tale.game.heroes.prototypes import HeroPrototype if achievement.type.source.is_ACCOUNT: return (AccountPrototype(model=account_model) for account_model in AccountPrototype._db_all()) if achievement.type.source.is_GAME_OBJECT: return (HeroPrototype(model=hero_model) for hero_model in HeroPrototype._db_all())
def setUp(self): super(AbilitiesTests, self).setUp() create_test_map() result, account_1_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') result, account_1_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.hero = HeroPrototype.get_by_account_id(account_1_id) self.enemy = HeroPrototype.get_by_account_id(account_1_id)
def test_process_arena_pvp_1x1(self): task = SupervisorTaskPrototype.create_arena_pvp_1x1( self.account_1, self.account_2) task.capture_member(self.account_1.id) task.capture_member(self.account_2.id) battle_1 = Battle1x1Prototype.create(self.account_1) battle_1.set_enemy(self.account_2) battle_1.save() battle_2 = Battle1x1Prototype.create(self.account_2) battle_2.set_enemy(self.account_1) battle_2.save() self.assertEqual( Battle1x1.objects.filter( state=BATTLE_1X1_STATE.PREPAIRING).count(), 2) self.assertEqual( Battle1x1.objects.filter( state=BATTLE_1X1_STATE.PROCESSING).count(), 0) old_hero = HeroPrototype.get_by_account_id(self.account_1.id) old_hero.health = 1 old_hero.save() task.process(bundle_id=666) new_hero = HeroPrototype.get_by_account_id(self.account_1.id) new_hero_2 = HeroPrototype.get_by_account_id(self.account_2.id) self.assertEqual(new_hero.actions.current_action.bundle_id, new_hero_2.actions.current_action.bundle_id) self.assertNotEqual(new_hero.actions.actions_list[0].bundle_id, new_hero.actions.actions_list[1].bundle_id) self.assertNotEqual(new_hero_2.actions.actions_list[0].bundle_id, new_hero_2.actions.actions_list[1].bundle_id) self.assertNotEqual(old_hero, new_hero) self.assertTrue(old_hero.actions.number < new_hero.actions.number) self.assertEqual(new_hero.health, new_hero.max_health) self.assertEqual(new_hero.actions.number, 2) self.assertEqual(new_hero_2.actions.number, 2) self.assertEqual( new_hero.actions.current_action.meta_action.serialize(), new_hero_2.actions.current_action.meta_action.serialize()) self.assertEqual( Battle1x1.objects.filter( state=BATTLE_1X1_STATE.PREPAIRING).count(), 0) self.assertEqual( Battle1x1.objects.filter( state=BATTLE_1X1_STATE.PROCESSING).count(), 2)
def test_is_old__not_own_hero(self): self.assertFalse( form_game_info(self.account_1, is_own=False)['account']['is_old']) TimePrototype(turn_number=666).save() self.assertTrue( form_game_info(self.account_1, is_own=False)['account']['is_old']) HeroPrototype.get_by_account_id(self.account_1.id).save() self.assertFalse( form_game_info(self.account_1, is_own=False)['account']['is_old'])
def setUp(self): super(AbilitiesTests, self).setUp() create_test_map() result, account_1_id, bundle_id = register_user( 'test_user_1', '*****@*****.**', '111111') result, account_1_id, bundle_id = register_user( 'test_user_2', '*****@*****.**', '111111') self.hero = HeroPrototype.get_by_account_id(account_1_id) self.enemy = HeroPrototype.get_by_account_id(account_1_id)
def test_save_all(self): self.hero_1.health = 1 self.hero_2.health = 1 self.hero_1.actions.updated = True self.storage.save_all() self.assertEqual(self.hero_1.health, HeroPrototype.get_by_id(self.hero_1.id).health) self.assertEqual(self.hero_2.health, HeroPrototype.get_by_id(self.hero_2.id).health) self.assertFalse(self.hero_1.actions.updated)
def use(self, api_version, building=None, battle=None): u''' Использование одной из способностей игрока (список способностей см. в разделе типов) - **адрес:** /game/abilities/<идентификатор способности>/api/use - **http-метод:** POST - **версии:** 1.0 - **параметры:** * GET: building — идентификатор здания, если способность касается здания * GET: battle — идентификатор pvp сражения, если способность касается операций с pvp сражением - **возможные ошибки**: нет Метод является «неблокирующей операцией» (см. документацию), формат ответа соответствует ответу для всех «неблокирующих операций». Цена использования способностей возвращается при запросе базовой информации. ''' task = self.ability.activate(HeroPrototype.get_by_account_id( self.account.id), data={ 'building_id': building, 'battle_id': battle }) return self.processing(task.status_url)
def setUp(self): super(TestVoteRequests, self).setUp() self.account2.prolong_premium(30) self.account2.save() self.hero = HeroPrototype.get_by_account_id(self.account2.id) self.hero.places_history.add_place(self.place1.id) self.hero.places_history.add_place(self.place2.id) self.hero.places_history.add_place(self.place3.id) self.hero.save() new_name = names.generator.get_test_name('new-name') data = linguistics_helpers.get_word_post_data(new_name, prefix='name') data.update({'caption': 'bill-caption', 'rationale': 'bill-rationale', 'chronicle_on_accepted': 'chronicle-on-accepted', 'place': self.place1.id}) self.client.post(reverse('game:bills:create') + ('?bill_type=%s' % PlaceRenaming.type.value), data) self.bill = BillPrototype(Bill.objects.all()[0]) self.request_logout() self.request_login('*****@*****.**')
def _initiate_battle_with_bot(self, record): # search free bot # since now bots needed only for PvP, we can do simplified search battled_accounts_ids = Battle1x1Prototype._model_class.objects.all().values_list('account_id', flat=True) try: bot_account = AccountPrototype(model=AccountPrototype._model_class.objects.filter(is_bot=True).exclude(id__in=battled_accounts_ids)[0]) except IndexError: bot_account = None if bot_account is None: return [record], [] bot_hero = HeroPrototype.get_by_account_id(bot_account.id) self.logger.info('start battle between account %d and bot %d' % (record.account_id, bot_account.id)) # create battle for bot self.add_to_arena_queue(bot_hero.id) bot_record = self.arena_queue[bot_account.id] self._initiate_battle(record, bot_record, calculate_ratings=False) return [], [record, bot_record]
def accept_battle(cls, pvp_balancer, battle_id, hero_id): accepted_battle = Battle1x1Prototype.get_by_id(battle_id) if accepted_battle is None: return ACCEPT_BATTLE_RESULT.BATTLE_NOT_FOUND if not accepted_battle.state.is_WAITING: return ACCEPT_BATTLE_RESULT.WRONG_ACCEPTED_BATTLE_STATE if not accepted_battle.account_id in pvp_balancer.arena_queue: return ACCEPT_BATTLE_RESULT.NOT_IN_QUEUE initiator_id = HeroPrototype.get_by_id(hero_id).account_id initiator_battle = Battle1x1Prototype.get_by_account_id(initiator_id) if initiator_battle is not None and not initiator_battle.state.is_WAITING: return ACCEPT_BATTLE_RESULT.WRONG_INITIATOR_BATTLE_STATE if initiator_id not in pvp_balancer.arena_queue: pvp_balancer.add_to_arena_queue(hero_id) pvp_balancer.force_battle(accepted_battle.account_id, initiator_id) return ACCEPT_BATTLE_RESULT.PROCESSED
def test_successfull_result(self): self.assertEqual(AccountAchievementsPrototype._db_count(), 0) self.assertEqual(AccountItemsPrototype._db_count(), 0) result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') # test result self.assertEqual(result, REGISTER_USER_RESULT.OK) self.assertTrue(bundle_id is not None) #test basic structure account = AccountPrototype.get_by_id(account_id) self.assertEqual(account.nick, 'test_user') self.assertEqual(account.email, '*****@*****.**') self.assertTrue(not account.is_fast) hero = HeroPrototype.get_by_account_id(account.id) # test hero equipment self.assertEqual( hero.equipment.get(EQUIPMENT_SLOT.PANTS).id, 'default_pants') self.assertEqual( hero.equipment.get(EQUIPMENT_SLOT.BOOTS).id, 'default_boots') self.assertEqual( hero.equipment.get(EQUIPMENT_SLOT.PLATE).id, 'default_plate') self.assertEqual( hero.equipment.get(EQUIPMENT_SLOT.GLOVES).id, 'default_gloves') self.assertEqual( hero.equipment.get(EQUIPMENT_SLOT.HAND_PRIMARY).id, 'default_weapon') self.assertTrue( hero.equipment.get(EQUIPMENT_SLOT.HAND_SECONDARY) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.HELMET) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.SHOULDERS) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.CLOAK) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.AMULET) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.RING) is None) self.assertEqual(HeroPreferencesPrototype._db_count(), 1) self.assertEqual( HeroPreferencesPrototype.get_by_hero_id( hero.id).energy_regeneration_type, hero.preferences.energy_regeneration_type) self.assertEqual(account.referer, None) self.assertEqual(account.referer_domain, None) self.assertEqual(account.referral_of_id, None) self.assertEqual(account.action_id, None) self.assertEqual(account.is_bot, False) self.assertEqual(AccountAchievementsPrototype._db_count(), 1) self.assertEqual(AccountItemsPrototype._db_count(), 1) self.assertEqual(market_models.Goods.objects.count(), 1)
def _initiate_battle_with_bot(self, record): # search free bot # since now bots needed only for PvP, we can do simplified search battled_accounts_ids = Battle1x1Prototype._model_class.objects.all( ).values_list('account_id', flat=True) try: bot_account = AccountPrototype( model=AccountPrototype._model_class.objects.filter( is_bot=True).exclude(id__in=battled_accounts_ids)[0]) except IndexError: bot_account = None if bot_account is None: return [record], [] bot_hero = HeroPrototype.get_by_account_id(bot_account.id) self.logger.info('start battle between account %d and bot %d' % (record.account_id, bot_account.id)) # create battle for bot self.add_to_arena_queue(bot_hero.id) bot_record = self.arena_queue[bot_account.id] self._initiate_battle(record, bot_record, calculate_ratings=False) return [], [record, bot_record]
def add_to_arena_queue(self, hero_id): hero = HeroPrototype.get_by_id(hero_id) if hero.account_id in self.arena_queue: return None battle = Battle1x1Prototype.create( AccountPrototype.get_by_id(hero.account_id)) if not battle.state.is_WAITING: raise PvPBalancerException( 'account %d already has battle not in waiting state' % hero.account_id) record = QueueRecord(account_id=battle.account_id, created_at=battle.created_at, battle_id=battle.id, hero_level=hero.level) if record.account_id in self.arena_queue: raise PvPBalancerException( 'account %d already added in balancer queue' % record.account_id) self.arena_queue[record.account_id] = record return battle
def test_get_random_mob__no_mob(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) self.assertEqual(mobs_storage.get_random_mob(hero), None)
def _form_game_account_info(game_time, account, in_pvp_queue, is_own, client_turns=None): from the_tale.game.heroes.prototypes import HeroPrototype data = { 'new_messages': account.new_messages_number if is_own else 0, 'id': account.id, 'last_visit': time.mktime((account.active_end_at - datetime.timedelta(seconds=accounts_settings.ACTIVE_STATE_TIMEOUT)).timetuple()), 'is_own': is_own, 'is_old': False, 'hero': None, 'in_pvp_queue': in_pvp_queue } hero_data = HeroPrototype.cached_ui_info_for_hero(account_id=account.id, recache_if_required=is_own, patch_turns=client_turns, for_last_turn=(not is_own)) data['hero'] = hero_data data['is_old'] = (data['hero']['actual_on_turn'] < game_time.turn_number) if not is_own: if 'cards' in hero_data: hero_data['cards'] = cards_container.CardsContainer.ui_info_null() if 'energy' in hero_data: hero_data['energy']['max'] = 0 hero_data['energy']['value'] = 0 hero_data['energy']['bonus'] = 0 hero_data['energy']['discount'] = 0 return data
def shop(context): hero = HeroPrototype.get_by_account_id(context.account.id) if context.account.is_premium: featured_group = relations.GOODS_GROUP.CHEST else: featured_group = relations.GOODS_GROUP.PREMIUM price_types = [group.type for group in price_list.PRICE_GROUPS] def _cmp(x, y): choices = { (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.CHEST, False): -1, (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.CHEST, True): 1, (relations.GOODS_GROUP.CHEST, relations.GOODS_GROUP.PREMIUM, False): 1, (relations.GOODS_GROUP.CHEST, relations.GOODS_GROUP.PREMIUM, True): -1, (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.ENERGY, False): -1, (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.ENERGY, True): 1, (relations.GOODS_GROUP.ENERGY, relations.GOODS_GROUP.PREMIUM, False): 1, (relations.GOODS_GROUP.ENERGY, relations.GOODS_GROUP.PREMIUM, True): -1 } return choices.get((x.type, y.type, context.account.is_premium), cmp(price_types.index(x.type), price_types.index(y.type))) price_groups = sorted(price_list.PRICE_GROUPS, cmp=_cmp) return dext_views.Page('shop/shop.html', content={'PRICE_GROUPS': price_groups, 'hero': hero, 'payments_settings': payments_settings, 'account': context.account, 'featured_group': featured_group, 'page_type': 'shop', 'resource': context.resource})
def test_own_hero_get_cached_data(self): hero = HeroPrototype.get_by_account_id(self.account_1.id) with mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.cached_ui_info_for_hero', mock.Mock( return_value={ 'actual_on_turn': hero.saved_at_turn, 'pvp': 'actual', 'ui_caching_started_at': 0 })) as cached_ui_info_for_hero: with mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.ui_info' ) as ui_info: data = form_game_info(self.account_1, is_own=True) self.assertEqual(data['account']['hero']['pvp'], 'actual') self.assertEqual(data['enemy'], None) self.assertEqual(cached_ui_info_for_hero.call_count, 1) self.assertEqual( cached_ui_info_for_hero.call_args, mock.call(account_id=self.account_1.id, recache_if_required=True, patch_turns=None, for_last_turn=False)) self.assertEqual(ui_info.call_count, 0)
def show(context): place_info = logic.place_info(context.place) return dext_views.Page( 'places/show.html', content={ 'place_info': place_info, 'place_meta_object': meta_relations.Place.create_from_object(context.place), 'RACE': game_relations.RACE, 'GENDER': game_relations.GENDER, 'PERSON_TYPE': persons_relations.PERSON_TYPE, 'CONNECTION_TYPE': persons_relations.SOCIAL_CONNECTION_TYPE, 'hero': HeroPrototype.get_by_account_id(context.account.id) if context.account else None, 'persons_storage': persons_storage.persons_storage, 'resource': context.resource })
def setUp(self): super(TestRequestsBase, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.account_1_id = account_id self.account_1 = AccountPrototype.get_by_id(account_id) self.hero_1 = HeroPrototype.get_by_account_id(self.account_1.id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2_id = account_id self.account_2 = AccountPrototype.get_by_id(account_id) self.hero_2 = HeroPrototype.get_by_account_id(self.account_2.id) self.client = client.Client() self.request_login('*****@*****.**')
def setUp(self): super(MobsPrototypeTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) mobs_storage.sync(force=True)
def setUp(self): super(TestShowRequests, self).setUp() self.hero = HeroPrototype.get_by_account_id(self.account2.id) self.hero.places_history.add_place(self.place1.id) self.hero.places_history.add_place(self.place2.id) self.hero.places_history.add_place(self.place3.id) self.hero.save()
def remove_game_data(account): from the_tale.game.heroes.prototypes import HeroPrototype hero = HeroPrototype.get_by_account_id(account.id) for action in reversed(hero.actions.actions_list): action.remove() hero.remove()
def _test_save(self): for hero_id in self.heroes: self._save_hero_data(hero_id) test_storage = LogicStorage() for hero_id in self.heroes: test_storage._add_hero(HeroPrototype.get_by_id(hero_id)) return self == test_storage
def test_can_not_voted(self): self.assertEqual(HeroPrototype.get_by_account_id(self.account1.id).places_history.history, []) # one vote automaticaly created for bill author bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator.get_test_name('new_name_1')) self.create_bills(1, self.account1, 'Caption-a1-%d', 'rationale-a1-%d', bill_data) bill = Bill.objects.all()[0] self.check_html_ok(self.request_html(reverse('game:bills:show', args=[bill.id])), texts=(('pgf-can-not-vote-message', 0),))
def test_get_random_mob__action_type(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) action_type = actions_relations.ACTION_TYPE.random() with mock.patch('the_tale.game.actions.prototypes.ActionBase.ui_type', action_type): mob = mobs_storage.get_random_mob(hero) self.assertEqual(mob.action_type, action_type)
def test_get_random_mob__terrain(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) terrain = map_relations.TERRAIN.random() with mock.patch('the_tale.game.heroes.prototypes.HeroPositionPrototype.get_terrain', lambda h: terrain): mob = mobs_storage.get_random_mob(hero) self.assertEqual(mob.terrain, terrain)
def setUp(self): super(PrototypeTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) artifacts_storage.sync(force=True) self.artifact_record = artifacts_storage.all()[0]
def test_process_arena_pvp_1x1(self): task = SupervisorTaskPrototype.create_arena_pvp_1x1(self.account_1, self.account_2) task.capture_member(self.account_1.id) task.capture_member(self.account_2.id) battle_1 = Battle1x1Prototype.create(self.account_1) battle_1.set_enemy(self.account_2) battle_1.save() battle_2 = Battle1x1Prototype.create(self.account_2) battle_2.set_enemy(self.account_1) battle_2.save() self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PREPAIRING).count(), 2) self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PROCESSING).count(), 0) old_hero = HeroPrototype.get_by_account_id(self.account_1.id) old_hero.health = 1 old_hero.save() task.process(bundle_id=666) new_hero = HeroPrototype.get_by_account_id(self.account_1.id) new_hero_2 = HeroPrototype.get_by_account_id(self.account_2.id) self.assertEqual(new_hero.actions.current_action.bundle_id, new_hero_2.actions.current_action.bundle_id) self.assertNotEqual(new_hero.actions.actions_list[0].bundle_id, new_hero.actions.actions_list[1].bundle_id) self.assertNotEqual(new_hero_2.actions.actions_list[0].bundle_id, new_hero_2.actions.actions_list[1].bundle_id) self.assertNotEqual(old_hero, new_hero) self.assertTrue(old_hero.actions.number < new_hero.actions.number) self.assertEqual(new_hero.health, new_hero.max_health) self.assertEqual(new_hero.actions.number, 2) self.assertEqual(new_hero_2.actions.number, 2) self.assertEqual(new_hero.actions.current_action.meta_action.serialize(), new_hero_2.actions.current_action.meta_action.serialize()) self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PREPAIRING).count(), 0) self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PROCESSING).count(), 2)
def setUp(self): super(SupervisorWorkerTests, self).setUp() self.p1, self.p2, self.p3 = create_test_map() result, account_1_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') result, account_2_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.hero_1 = HeroPrototype.get_by_account_id(account_1_id) self.hero_2 = HeroPrototype.get_by_account_id(account_2_id) self.account_1 = AccountPrototype.get_by_id(account_1_id) self.account_2 = AccountPrototype.get_by_id(account_2_id) environment.deinitialize() environment.initialize() self.worker = environment.workers.supervisor self.worker.logger = mock.Mock()
def setUp(self): super(EffectsTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) artifacts_storage.sync(force=True) self.artifact = self.hero.equipment.values()[0]
def load_account_data(self, account): hero = HeroPrototype.get_by_account_id(account.id) hero.update_with_account_data(is_fast=account.is_fast, premium_end_at=account.premium_end_at, active_end_at=account.active_end_at, ban_end_at=account.ban_game_end_at, might=account.might, actual_bills=account.actual_bills) self._add_hero(hero) return hero
def show(context): place_info = logic.place_info(context.place) return dext_views.Page('places/show.html', content={'place_info': place_info, 'place_meta_object': meta_relations.Place.create_from_object(context.place), 'RACE': game_relations.RACE, 'GENDER': game_relations.GENDER, 'PERSON_TYPE': persons_relations.PERSON_TYPE, 'CONNECTION_TYPE': persons_relations.SOCIAL_CONNECTION_TYPE, 'hero': HeroPrototype.get_by_account_id(context.account.id) if context.account else None, 'persons_storage': persons_storage.persons_storage, 'resource': context.resource} )
def setUp(self): super(BalancerTestsBase, self).setUp() self.p1, self.p2, self.p3 = create_test_map() result, account_1_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') result, account_2_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_1_id) self.account_2 = AccountPrototype.get_by_id(account_2_id) self.hero_1 = HeroPrototype.get_by_account_id(account_1_id) self.hero_2 = HeroPrototype.get_by_account_id(account_2_id) environment.deinitialize() environment.initialize() Battle1x1Prototype.create(self.account_1) self.worker = environment.workers.pvp_balancer self.worker.process_initialize('pvp_balancer')
def test_choose_mob__when_actions__total_actions(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) MobRecordPrototype.create_random('action_1', global_action_probability=0.66) MobRecordPrototype.create_random('action_2', global_action_probability=0.66) counter = collections.Counter([mobs_storage.get_random_mob(hero).id for i in xrange(10000)]) self.assertEqual(sum([count for uuid, count in counter.iteritems() if uuid not in ('action_1', 'action_2')], 0), 0) self.assertTrue(abs(counter['action_2'] - counter['action_1']) < 0.2 * counter['action_2'])
def test_is_old__pvp(self): self.pvp_create_battle(self.account_1, self.account_2, BATTLE_1X1_STATE.PROCESSING) self.pvp_create_battle(self.account_2, self.account_1, BATTLE_1X1_STATE.PROCESSING) hero_1 = HeroPrototype.get_by_account_id(self.account_1.id) hero_2 = HeroPrototype.get_by_account_id(self.account_2.id) self.assertFalse(form_game_info(self.account_1)['account']['is_old']) self.assertFalse(form_game_info(self.account_1)['enemy']['is_old']) TimePrototype(turn_number=666).save() self.assertTrue(form_game_info(self.account_1)['account']['is_old']) self.assertTrue(form_game_info(self.account_1)['enemy']['is_old']) hero_1.save() hero_2.save() self.assertFalse(form_game_info(self.account_1)['account']['is_old']) self.assertFalse(form_game_info(self.account_1)['enemy']['is_old'])
def test_get_random_mob__boss(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) boss = mobs_storage.get_random_mob(hero, is_boss=True) self.assertTrue(boss.is_boss) normal_mob = boss.record.create_mob(hero) self.assertFalse(normal_mob.is_boss) self.assertTrue(boss.max_health > normal_mob.max_health)
def test_show__places_history(self): texts = [(self.place1.name, 1), (self.place2.name, 1), (self.place3.name, 0), ('pgf-no-common-places-message', 0)] hero = HeroPrototype.get_by_account_id(self.account_1.id) hero.places_history.add_place(self.place1.id) hero.places_history.add_place(self.place2.id) hero.places_history.add_place(self.place1.id) hero.save() self.check_html_ok(self.request_html(reverse('accounts:show', args=[self.account_1.id])), texts=texts)
def test_game_info_caching(self): self.pvp_create_battle(self.account_1, self.account_2, BATTLE_1X1_STATE.PROCESSING) self.pvp_create_battle(self.account_2, self.account_1, BATTLE_1X1_STATE.PROCESSING) hero_1 = HeroPrototype.get_by_account_id(self.account_1.id) hero_2 = HeroPrototype.get_by_account_id(self.account_2.id) def get_ui_info(hero, **kwargs): if hero.id == hero_1.id: return { 'actual_on_turn': hero_1.saved_at_turn, 'pvp__actual': 'actual', 'pvp__last_turn': 'last_turn', 'changed_fields': [], 'ui_caching_started_at': 0 } else: return self.create_not_own_ui_info(hero_2) with mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.ui_info', get_ui_info): data = form_game_info(self.account_1, is_own=True) self.assertEqual(data['account']['hero']['pvp'], 'actual') self.assertEqual(data['enemy']['hero']['pvp'], 'last_turn') self.assertFalse('pvp__actual' in data['account']['hero']['pvp']) self.assertFalse('pvp__last_turn' in data['account']['hero']['pvp']) self.assertFalse('pvp__actual' in data['enemy']['hero']['pvp']) self.assertFalse('pvp__last_turn' in data['enemy']['hero']['pvp']) self.assertNotEqual(data['enemy']['hero']['cards'], 'fake') self.assertEqual(data['enemy']['hero']['energy']['max'], 0) self.assertEqual(data['enemy']['hero']['energy']['value'], 0) self.assertEqual(data['enemy']['hero']['energy']['bonus'], 0) self.assertEqual(data['enemy']['hero']['energy']['discount'], 0)
def initialize(self, account, thread, page, inline=False): from the_tale.game.heroes.prototypes import HeroPrototype self.account = account self.thread = thread url_builder = UrlBuilder(reverse('forum:threads:show', args=[self.thread.id]), arguments={'page': page}) page -= 1 self.paginator = Paginator(page, thread.posts_count+1, forum_settings.POSTS_ON_PAGE, url_builder) if self.paginator.wrong_page_number: return False post_from, post_to = self.paginator.page_borders(page) self.post_from = post_from self.posts = [PostPrototype(post_model) for post_model in Post.objects.filter(thread=self.thread._model).order_by('created_at')[post_from:post_to]] self.authors = {author.id:author for author in AccountPrototype.get_list_by_id([post.author_id for post in self.posts])} self.game_objects = {game_object.account_id:game_object for game_object in HeroPrototype.get_list_by_id([post.author_id for post in self.posts])} pages_on_page_slice = self.posts if post_from == 0: pages_on_page_slice = pages_on_page_slice[1:] self.has_post_on_page = any([post.author.id == self.account.id for post in pages_on_page_slice]) self.new_post_form = forms.NewPostForm() self.start_posts_from = page * forum_settings.POSTS_ON_PAGE self.inline = inline self.can_delete_posts = can_delete_posts(self.account, self.thread) self.can_change_posts = can_change_posts(self.account) self.can_delete_thread = not self.inline and can_delete_thread(self.account) self.can_change_thread = not self.inline and can_change_thread(self.account, self.thread) self.ignore_first_post = (self.inline and self.paginator.current_page_number==0) self.can_post = self.account.is_authenticated() and not self.account.is_fast self.no_posts = (len(self.posts) == 0) or (self.ignore_first_post and len(self.posts) == 1) self.can_subscribe = self.account.is_authenticated() and not self.account.is_fast self.has_subscription = SubscriptionPrototype.has_subscription(self.account, self.thread) return True
def setUp(self): super(BalancerTestsBase, self).setUp() self.p1, self.p2, self.p3 = create_test_map() result, account_1_id, bundle_id = register_user( 'test_user', '*****@*****.**', '111111') result, account_2_id, bundle_id = register_user( 'test_user_2', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_1_id) self.account_2 = AccountPrototype.get_by_id(account_2_id) self.hero_1 = HeroPrototype.get_by_account_id(account_1_id) self.hero_2 = HeroPrototype.get_by_account_id(account_2_id) environment.deinitialize() environment.initialize() Battle1x1Prototype.create(self.account_1) self.worker = environment.workers.pvp_balancer self.worker.process_initialize('pvp_balancer')