def test_process_second_step_success(self): with mock.patch('the_tale.game.abilities.deck.help.Help.use', lambda self, task, storage, pvp_balancer, highlevel: (ComplexChangeTask.RESULT.CONTINUE, ComplexChangeTask.STEP.HIGHLEVEL, ())): self.assertEqual(self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.CONTINUE) self.assertTrue(self.task.step.is_HIGHLEVEL) self.assertEqual(self.task.state, ComplexChangeTask.STATE.UNPROCESSED) self.assertEqual(self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertEqual(self.task.state, ComplexChangeTask.STATE.PROCESSED)
def test_choose_second_choice_before_first_completed(self): task = self.create_task(option_uid=self.option_1_2_uid) self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertTrue(task.state.is_PROCESSED) task = self.create_task(option_uid=self.option_2_1_uid) self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertTrue(task.state.is_WRONG_POINT)
def test_already_chosen(self): task = self.create_task(option_uid=self.option_1_1_uid) self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertTrue(task.state.is_PROCESSED) task = self.create_task(option_uid=self.option_1_2_uid) self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertTrue(task.state.is_ALREADY_CHOSEN)
def test_process_success(self): self.assertEqual(self.task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertEqual(self.task.state, REGISTRATION_TASK_STATE.PROCESSED) self.assertTrue(self.task.account) self.assertTrue(self.task.account.is_fast) self.assertEqual(Account.objects.all().count(), 1)
def test_wrong_ability_id(self): task = UsePvPAbilityTask(battle_id=self.battle.id, account_id=self.account_1.id, ability_id=u'wrong_ability_id') task.process(FakePostpondTaskPrototype(), self.storage) self.assertEqual(task.state, USE_PVP_ABILITY_TASK_STATE.WRONG_ABILITY_ID)
def test_success__remove_duplicates(self): cards = [cards_objects.Card(cards_relations.CARD_TYPE.ADD_GOLD_COMMON), cards_objects.Card(cards_relations.CARD_TYPE.ADD_GOLD_COMMON), cards_objects.Card(cards_relations.CARD_TYPE.ADD_GOLD_COMMON), cards_objects.Card(cards_relations.CARD_TYPE.ADD_EXPERIENCE_COMMON), cards_objects.Card(cards_relations.CARD_TYPE.ADD_EXPERIENCE_COMMON), cards_objects.Card(cards_relations.CARD_TYPE.ADD_BONUS_ENERGY_COMMON), cards_objects.Card(cards_relations.CARD_TYPE.CHANGE_HERO_SPENDINGS_TO_INSTANT_HEAL), cards_objects.Card(cards_relations.CARD_TYPE.LEVEL_UP)] for card in cards: self.hero.cards.add_card(card) task = CombineCardsTask(self.hero.id, cards=[cards[1].uid, cards[2].uid, cards[5].uid]) with self.check_delta(self.hero.cards.cards_count, -2): self.assertEqual(task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertTrue(self.hero.cards.has_card(cards[0].uid)) self.assertFalse(self.hero.cards.has_card(cards[1].uid)) self.assertFalse(self.hero.cards.has_card(cards[2].uid)) self.assertTrue(self.hero.cards.has_card(cards[3].uid)) self.assertTrue(self.hero.cards.has_card(cards[4].uid)) self.assertFalse(self.hero.cards.has_card(cards[5].uid)) self.assertTrue(self.hero.cards.has_card(cards[6].uid)) self.assertTrue(self.hero.cards.has_card(cards[7].uid)) self.assertTrue(task.state.is_PROCESSED)
def test_banned(self): self.hero.ban_state_end_at = datetime.datetime.now( ) + datetime.timedelta(days=1) self.hero.save() self.assertEqual( self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertEqual(self.task.state, ComplexChangeTask.STATE.BANNED)
def test_process_id_not_in_choices(self): task = ChooseHeroAbilityTask(self.hero.id, self.get_unchoosed_ability_id()) self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertEqual(task.state, CHOOSE_HERO_ABILITY_STATE.NOT_IN_CHOICE_LIST)
def test_process_no_energy(self): self.hero._model.energy = 0 self.hero._model.energy_bonus = 0 self.hero.save() self.assertEqual( self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertEqual(self.task.state, ComplexChangeTask.STATE.HERO_CONDITIONS_NOT_PASSED)
def test_process_second_step_error(self): card_effect = random.choice(effects.EFFECTS.values()) card = objects.Card(card_effect.TYPE) self.hero.cards.add_card(card) task = card.activate(self.hero, data=self.task_data).internal_logic with mock.patch.object(card_effect, 'use', lambda **kwargs: (UseCardTask.RESULT.CONTINUE, UseCardTask.STEP.HIGHLEVEL, ())): self.assertEqual(task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.CONTINUE) self.assertTrue(task.step.is_HIGHLEVEL) self.assertEqual(task.state, UseCardTask.STATE.UNPROCESSED) with mock.patch.object(card_effect, 'use', lambda **kwargs: (UseCardTask.RESULT.FAILED, None, ())): self.assertEqual(task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertEqual(task.state, UseCardTask.STATE.CAN_NOT_PROCESS)
def test_response_data(self): card_effect = random.choice(effects.EFFECTS.values()) card = objects.Card(card_effect.TYPE) self.hero.cards.add_card(card) with mock.patch.object(card_effect, 'use', lambda **kwargs: (UseCardTask.RESULT.SUCCESSED, None, ())): task = card.activate(self.hero, data=self.task_data).internal_logic task.process(FakePostpondTaskPrototype(), self.storage) self.assertEqual(task.processed_data, {})
def test_process_success(self): card_effect = random.choice(effects.EFFECTS.values()) card = objects.Card(card_effect.TYPE) self.hero.cards.add_card(card) task = card.activate(self.hero, data=self.task_data).internal_logic with mock.patch.object(card_effect, 'use', lambda **kwargs: (UseCardTask.RESULT.SUCCESSED, None, ())): self.assertEqual(task.process(FakePostpondTaskPrototype(), storage=self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertEqual(task.state, UseCardTask.STATE.PROCESSED)
def test_process_can_not_process(self): with mock.patch( 'the_tale.game.abilities.deck.help.Help.use', lambda self, task, storage, pvp_balancer, highlevel: (ComplexChangeTask.RESULT.FAILED, None, ())): self.assertEqual( self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertEqual(self.task.state, ComplexChangeTask.STATE.CAN_NOT_PROCESS)
def test__can_not_get(self): self.hero.cards.change_help_count(c.CARDS_HELP_COUNT_TO_NEW_CARD - 1) task = GetCardTask(self.hero.id) with self.check_not_changed(lambda: self.hero.cards.help_count): self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertFalse(self.hero.cards.has_cards) self.assertTrue(task.state.is_CAN_NOT_GET)
def test_no_choices(self): task = self.create_task(option_uid=self.option_1_1_uid) knowledge_base = self.hero.quests.current_quest.knowledge_base finish_state = knowledge_base.filter(facts.Finish).next() self.hero.quests.current_quest.machine.pointer.change_in_knowlege_base( knowledge_base, state=finish_state.uid, jump=None) self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertTrue(task.state.is_NO_CHOICES_IN_QUEST)
def test_process_success__with_referer(self): referer = 'http://example.com/forum/post/1/' task = RegistrationTask(account_id=None, referer=referer, referral_of_id=None, action_id=None) self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED) self.assertTrue(task.account) self.assertEqual(task.account.referer, referer) self.assertEqual(task.account.referer_domain, 'example.com')
def test_process_not_for_heroes(self): task = ChooseHeroAbilityTask(self.hero.id, self.get_only_for_mobs_ability_id()) with mock.patch( 'the_tale.game.heroes.habilities.AbilitiesPrototype.get_for_choose', lambda x: [ABILITIES[task.ability_id]]): self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertEqual(task.state, CHOOSE_HERO_ABILITY_STATE.NOT_FOR_PLAYERS)
def test_process_success__with_action(self): result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id='action') self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED) self.assertTrue(task.account) self.assertEqual(task.account.action_id, 'action')
def test_choose_second_choice_after_first_completed(self): task = self.create_task(option_uid=self.option_1_2_uid) self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertTrue(task.state.is_PROCESSED) current_time = TimePrototype.get_current_time() while True: self.assertNotEqual(self.hero.actions.current_action, ActionIdlenessPrototype.TYPE) task = self.create_task(option_uid=self.option_2_1_uid) if task.process(FakePostpondTaskPrototype(), self.storage) == POSTPONED_TASK_LOGIC_RESULT.ERROR: break self.storage.process_turn() self.storage.save_changed_data() current_time.increment_turn()
def test__can_not_combine(self): for combine_status in cards_relations.CARDS_COMBINING_STATUS.records: if combine_status.is_ALLOWED: continue task = CombineCardsTask(self.hero.id, cards=[]) with mock.patch('the_tale.game.cards.container.CardsContainer.can_combine_cards', lambda self, cards: combine_status): with self.check_not_changed(self.hero.cards.cards_count): self.assertEqual(task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertFalse(self.hero.cards.has_cards) self.assertTrue(task.state.is_CAN_NOT_COMBINE)
def test_process_no_freee_ability_points(self): task = ChooseHeroAbilityTask(self.hero.id, self.get_new_ability_id()) with mock.patch( 'the_tale.game.heroes.habilities.AbilitiesPrototype.can_choose_new_ability', False): self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertEqual( task.state, CHOOSE_HERO_ABILITY_STATE.MAXIMUM_ABILITY_POINTS_NUMBER)
def test_no_quests(self): self.turn_to_quest(self.storage, self.hero.id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.storage.load_account_data(AccountPrototype.get_by_id(account_id)) task = self.create_task(option_uid=self.option_1_1_uid, account_id=account_id) self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertTrue(task.state.is_QUEST_NOT_FOUND)
def test_success(self): self.hero.quests.updated = False self.assertTrue( all(not action.replane_required for action in self.hero.actions.actions_list)) task = self.create_task(option_uid=self.option_1_1_uid) self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertTrue(task.state.is_PROCESSED) self.assertTrue( all(action.replane_required for action in self.hero.actions.actions_list)) self.assertTrue(self.hero.quests.updated)
def test_success(self): self.hero.cards.change_help_count(c.CARDS_HELP_COUNT_TO_NEW_CARD + 1) task = GetCardTask(self.hero.id) with self.check_delta(lambda: self.hero.cards.help_count, -c.CARDS_HELP_COUNT_TO_NEW_CARD): self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertTrue(self.hero.cards.has_cards) self.assertTrue(self.hero.cards.all_cards().next().name.lower() in task.processed_data['message'].lower()) self.assertTrue(self.hero.cards.all_cards().next().effect.DESCRIPTION. lower() in task.processed_data['message'].lower()) self.assertTrue(task.state.is_PROCESSED)
def test_check_change(self): task = ChangeHeroTask(self.hero.id, name=self.noun, race=self.race, gender=self.gender) self.assertNotEqual(self.hero.utg_name, self.noun) self.assertNotEqual(self.hero.gender, self.gender) self.assertNotEqual(self.hero.race, self.race) self.assertFalse(self.hero.settings_approved) with mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.reset_accessors_cache') as reset_accessors_cache: self.assertEqual(task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertEqual(reset_accessors_cache.call_count, 1) self.assertEqual(task.state, CHANGE_HERO_TASK_STATE.PROCESSED) self.assertEqual(self.hero.utg_name.forms, self.noun.forms) self.assertEqual(self.hero.utg_name.properties.get(utg_relations.GENDER), self.gender.utg_id) self.assertEqual(self.hero.name, self.noun.normal_form()) self.assertEqual(self.hero.race, self.race) self.assertEqual(self.hero.gender, self.gender) self.assertTrue(self.hero.settings_approved)
def test_block_expired_accounts(self): task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id=None) self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) task.account._model.created_at = datetime.datetime.fromtimestamp(0) task.account._model.save() self.assertEqual(AccountAchievementsPrototype._db_count(), 1) logic.block_expired_accounts() self.assertEqual(Hero.objects.all().count(), 0) self.assertEqual(Account.objects.all().count(), 0) self.assertEqual(AccountAchievementsPrototype._db_count(), 0)
def test_process_already_max_level(self): task = ChooseHeroAbilityTask(self.hero.id, battle_abilities.HIT.get_id()) self.hero.abilities.abilities[battle_abilities.HIT.get_id( )].level = battle_abilities.HIT.MAX_LEVEL self.hero.abilities.updated = True self.hero.save() with mock.patch( 'the_tale.game.heroes.habilities.AbilitiesPrototype.get_for_choose', lambda x: [ABILITIES[task.ability_id]]): with mock.patch( 'the_tale.game.heroes.habilities.AbilitiesPrototype.can_choose_new_ability', True): self.assertEqual( task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR) self.assertEqual(task.state, CHOOSE_HERO_ABILITY_STATE.ALREADY_MAX_LEVEL)
def test_success__2_cards(self): card_1 = cards_objects.Card(cards_relations.CARD_TYPE.ADD_GOLD_COMMON) card_2 = cards_objects.Card(cards_relations.CARD_TYPE.ADD_GOLD_COMMON) self.hero.cards.add_card(card_1) self.hero.cards.add_card(card_2) task = CombineCardsTask(self.hero.id, cards=[card_1.uid, card_2.uid]) with self.check_delta(self.hero.cards.cards_count, -1): self.assertEqual(task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertTrue(self.hero.cards.has_cards) self.assertEqual(self.hero.cards.cards_count(), 1) self.assertTrue(self.hero.cards.all_cards().next().type.rarity.is_COMMON) self.assertTrue(self.hero.cards.all_cards().next().type.text.lower() in task.processed_data['message'].lower()) self.assertTrue(self.hero.cards.all_cards().next().effect.DESCRIPTION.lower() in task.processed_data['message'].lower()) self.assertTrue(task.state.is_PROCESSED)
def test_process_success(self): self.hero_1.pvp.set_energy(1) old_hero_1_last_message = self.hero_1.messages.messages[-1] old_hero_2_last_message = self.hero_2.messages.messages[-1] self.assertEqual( self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.PROCESSED) self.assertNotEqual(old_hero_1_last_message, self.hero_1.messages.messages[-1]) self.assertNotEqual(old_hero_2_last_message, self.hero_2.messages.messages[-1]) self.assertNotEqual(old_hero_1_last_message.ui_info()[-1], self.hero_1.messages.ui_info()[-1][-1]) self.assertEqual(old_hero_2_last_message.ui_info()[-1], self.hero_2.messages.ui_info()[-1][-1]) self.assertEqual(self.hero_1.pvp.energy, 0)
def test_process_exceptin(self): self.assertRaises(Exception, self.task.process, FakePostpondTaskPrototype()) self.assertEqual(Account.objects.all().count(), 0)