def test_created_at_turn(self): turn.increment() turn.increment() post = PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text') self.assertEqual(post.created_at_turn, turn.number())
def quest_test_method(self): # defends from first quest rule self.hero.statistics.change_quests_done(1) heroes_logic.save_hero(self.hero) test_upgrade_equipment = random.randint( 0, 1) # test child quest or upgrade equipment for SearchSmith while self.hero.actions.current_action.TYPE != ActionQuestPrototype.TYPE or not self.hero.quests.has_quests: if quest == SearchSmith and test_upgrade_equipment: self.hero.money = QuestPrototype.upgrade_equipment_cost( self.hero) * 2 self.hero.next_spending = heroes_relations.ITEMS_OF_EXPENDITURE.INSTANT_HEAL self.storage.process_turn() turn.increment() # test if quest is serializable s11n.to_json(self.hero.quests.current_quest.serialize()) self.complete_quest() self.assertEqual(self.hero.actions.current_action.TYPE, ActionIdlenessPrototype.TYPE) if quest == SearchSmith and test_upgrade_equipment: self.assertTrue( self.hero.statistics.money_spend_for_artifacts > 0 or self.hero.statistics.money_spend_for_sharpening > 0)
def test_percents_consistency(self): # just test that quest will be ended while not self.action_idl.leader: self.storage.process_turn() turn.increment() self.assertEqual(self.storage.tests_get_last_action().percents, self.hero.last_action_percents)
def test_not_enough_voices_percents(self): turn.increment() turn.increment() VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST) VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.REFRAINED) self.assertEqual(Post.objects.all().count(), 1) with self.check_not_changed(lambda: self.place1.attrs.stability): with mock.patch( 'the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method' ) as cmd_run_account_method: self.assertFalse(self.bill.apply()) self.assertEqual(cmd_run_account_method.call_count, 0) self.assertTrue(self.bill.state.is_REJECTED) self.assertEqual(Post.objects.all().count(), 2) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_REJECTED) places_storage.places.sync(force=True) self.place1.refresh_attributes() self.assertEqual(bill.applyed_at_turn, turn.number()) self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)
def _test_companion_death_speed(self): companion_record = logic.create_random_companion_record( 'test companion', state=relations.STATE.ENABLED, dedication=relations.DEDICATION.BRAVE) #,#,; companion = logic.create_companion(companion_record) self.hero.set_companion(companion) self.hero.preferences.set_companion_dedication( heroes_relations.COMPANION_DEDICATION.NORMAL) old_health = self.hero.companion.health while self.hero.companion: self.hero.companion.coherence = 50 self.storage.process_turn() turn.increment() self.hero.randomized_level_up() if not self.hero.is_alive: if hasattr(self.hero.actions.current_action, 'fast_resurrect'): self.hero.actions.current_action.fast_resurrect() if self.hero.companion: old_health = self.hero.companion.health
def test_sync__turn_cache_reset(self): self.storage.sync() logic.add_power_impacts([ tt_api_impacts.PowerImpact.hero_2_person( type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE, hero_id=1, person_id=10, amount=666) ]) turn.increment() self.storage.sync() self.assertEqual(self.storage.turn, 1) self.assertEqual(self.storage._inner_power, { 10: 100 + 666, 20: 200, 30: 0, 40: -400, 50: 0 }) self.assertEqual(self.storage._outer_power, { 10: 0, 20: 0, 30: -300, 40: 0, 50: 500 })
def test_move_change_place_coordinates_and_back(self): while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionIdlenessPrototype.TYPE) self.assertTrue(self.hero.position.is_walking or self.hero.position.place) # can end in start place prototypes.ActionMoveNearPlacePrototype.create(hero=self.hero, place=self.p1, back=True) self.p1.x = self.p1.x + 1 self.p1.y = self.p1.y + 1 places_logic.save_place(self.p1) while self.hero.position.place is None or self.hero.position.place.id != self.p1.id: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.assertTrue(not self.hero.position.is_walking) self.storage._test_save()
def test_full(self): while not self.action_idl.leader: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.storage._test_save()
def complete_quest(self): while not self.action_idl.leader: self.storage.process_turn() turn.increment() self.hero.ui_info( actual_guaranteed=True) # test if ui info formed correctly
def _end_battle(self, hero_1_health, hero_2_health): self.hero_1.health = hero_1_health self.hero_2.health = hero_2_health self.meta_action_battle.process() turn.increment() self.meta_action_battle.process()
def test_companion_healing_by_hero__not_healed(self): self.hero.companion.health = 1 with self.check_delta(lambda: self.hero.companion.health, c.COMPANIONS_HEALTH_PER_HEAL): self.action_heal_companion.state = self.action_heal_companion.STATE.PROCESSED self.storage.process_turn(continue_steps_if_needed=False) turn.increment()
def test_region_for_turn(self): turn.increment() self.check_ajax_error(self.request_ajax_json(logic.region_url(turn.number())), 'no_region_found') update_map(index=1) self.check_ajax_ok(self.request_ajax_json(logic.region_url(turn.number())))
def test_post_created_at_turn(self): turn.increment(2) ThreadPrototype.create(self.subcategory, 'thread-2-caption', self.account, 'thread-2-text') self.assertEqual(PostPrototype._db_latest().created_at_turn, turn.number())
def test_full_move(self): while self.hero.position.place is None or self.hero.position.place.id != self.p3.id: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.storage._test_save()
def test_game_time(self): self.assertEqual(turn.game_datetime(), tt_calendar.DateTime(0, 0, 0, 0, 0, 0)) turn.increment() self.assertEqual(turn.game_datetime(), tt_calendar.DateTime(0, 0, 0, 0, 2, 0))
def test_buy_meal__from_moveto(self): prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.place_3) with self.check_decreased(lambda: self.hero.money), \ self.check_increased(lambda: self.hero.statistics.money_spend_for_companions): while self.hero.actions.current_action.TYPE != prototypes.ActionInPlacePrototype.TYPE: turn.increment() self.storage.process_turn(continue_steps_if_needed=False)
def test_full(self): while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertTrue(self.action_idl.leader) self.storage._test_save()
def test_full_battle(self): while len(self.hero.actions.actions_list) != 1: self.storage.process_turn() turn.increment() self.assertTrue(self.action_idl.leader) self.storage._test_save()
def test_push_message(self): self.messages.push_message(self.create_message('1')) self.messages.push_message(self.create_message('2')) turn.increment() self.messages.push_message(self.create_message('3')) self.assertEqual([msg.message for msg in self.messages.messages], ['1', '2', '3'])
def test_full_quest(self): # just test that quest will be ended while not self.action_idl.leader: self.storage.process_turn() turn.increment() self.storage._test_save() self.assertFalse(self.hero.quests.has_quests)
def test_full(self): self.hero.companion.health = 1 with self.check_delta(lambda: self.hero.companion.health, c.COMPANIONS_HEALTH_PER_HEAL): while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertTrue(self.action_idl.leader) self.storage._test_save()
def test_full__regeneration(self): self.hero.companion.health = 1 while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.companion.health, 1+c.COMPANIONS_HEALTH_PER_HEAL+c.COMPANIONS_REGEN_ON_HEAL_AMOUNT) self.storage._test_save()
def test_inplace(self): self.storage.process_turn(continue_steps_if_needed=False) self.hero.position.percents = 1 turn.increment() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.storage._test_save()
def test_full_battle(self): while self.action_proxy_1.state != meta_actions.ArenaPvP1x1.STATE.PROCESSED: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertEqual(self.meta_action_battle.state, meta_actions.ArenaPvP1x1.STATE.PROCESSED) self.assertTrue(self.hero_1.is_alive and self.hero_2.is_alive) self.assertTrue(self.action_idl_1.leader) self.assertTrue(self.action_idl_2.leader)
def turn_to_quest(self, storage, hero_id): hero = storage.heroes[hero_id] while hero.actions.current_action.TYPE != ActionQuestPrototype.TYPE or not self.hero.quests.has_quests: storage.process_turn() turn.increment() storage.save_changed_data() return hero.quests.current_quest
def test_full__start_equal_to_finish(self): self.action_move.destination_x = self.p1.x self.action_move.destination_y = self.p1.y while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertTrue(self.action_idl.leader) self.storage._test_save()
def test_full(self): for i in range(7): self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertTrue(self.action_donothing.leader) self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertTrue(self.action_idl.leader) self.storage._test_save()
def test_one_hero_killed(self): self.hero_1.health = 0 self.meta_action_battle.process() self.assertEqual(self.meta_action_battle.state, meta_actions.ArenaPvP1x1.STATE.BATTLE_ENDING) turn.increment() self.meta_action_battle.process() self.assertEqual(self.meta_action_battle.state, meta_actions.ArenaPvP1x1.STATE.PROCESSED) self.assertTrue(self.hero_1.is_alive and self.hero_2.is_alive) self.assertEqual(self.hero_1.health, self.hero_1.max_health / 2) self.assertEqual(self.hero_2.health, self.hero_2.max_health)
def test_creation(self): Setting.objects.all().delete() settings.refresh() settings_number = Setting.objects.all().count() self.assertEqual(turn.number(), 0) self.assertEqual(Setting.objects.all().count(), settings_number) turn.increment() self.assertEqual(turn.number(), 1) self.assertEqual(Setting.objects.all().count(), settings_number + 1)
def test_ability_heal_companion__full_action(self): self.hero.companion.health = 1 with self.check_increased(lambda: self.action_heal_companion.percents): with self.check_increased(lambda: self.hero.companion.health): while self.action_heal_companion.state != self.action_heal_companion.STATE.PROCESSED: turn.increment() ability = self.PROCESSOR() with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION): self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage)))