Exemplo n.º 1
0
    def check_job_energy(self, place_id, person_id):
        old_energy = game_tt_api.energy_balance(self.hero.account_id)

        with self.check_calls_count(
                'the_tale.game.heroes.tt_api.push_message_to_diary', 1):
            with self.check_increased(
                    lambda: game_tt_api.energy_balance(self.hero.account_id)):
                self.hero.job_energy(
                    place_id=place_id,
                    person_id=person_id,
                    message_type=
                    'job_diary_person_hero_energy_positive_enemies',
                    job_power=1)
                time.sleep(0.1)

        middle_energy = game_tt_api.energy_balance(self.hero.account_id)

        with self.check_calls_count(
                'the_tale.game.heroes.tt_api.push_message_to_diary', 1):
            with self.check_increased(
                    lambda: game_tt_api.energy_balance(self.hero.account_id)):
                self.hero.job_energy(
                    place_id=place_id,
                    person_id=person_id,
                    message_type=
                    'job_diary_person_hero_energy_positive_enemies',
                    job_power=2)
                time.sleep(0.1)

        self.assertTrue(
            middle_energy -
            old_energy < game_tt_api.energy_balance(self.hero.account_id) -
            middle_energy)
Exemplo n.º 2
0
    def test_activate_and_complete(self):
        energy = game_tt_api.energy_balance(self.account.id)

        task = self.ability.activate(self.hero, self.task_data)
        self.assertNotEqual(task.internal_logic.data['transaction_id'], None)

        self.assertEqual(game_tt_api.energy_balance(self.account.id),
                         energy - self.ability.TYPE.cost)

        task.process(FakePostpondTaskPrototype(), storage=self.storage)

        self.assertTrue(task.state.is_processed)

        self.assertEqual(game_tt_api.energy_balance(self.account.id),
                         energy - self.ability.TYPE.cost)
Exemplo n.º 3
0
    def test_activate_and_complete__zero_cost(self):
        energy = game_tt_api.energy_balance(self.account.id)
        game_tt_api.change_energy_balance(account_id=self.account.id,
                                          type='test',
                                          energy=-energy,
                                          autocommit=True)

        task = self.ability.activate(self.hero, self.task_data)
        self.assertEqual(task.internal_logic.data['transaction_id'], None)

        task.process(FakePostpondTaskPrototype(), storage=self.storage)

        self.assertTrue(task.state.is_processed)

        self.assertEqual(game_tt_api.energy_balance(self.account.id), 0)
Exemplo n.º 4
0
    def test_activate__no_energy(self):
        energy = game_tt_api.energy_balance(self.account.id)
        game_tt_api.change_energy_balance(account_id=self.account.id,
                                          type='test',
                                          energy=-energy,
                                          autocommit=True)

        task = self.ability.activate(self.hero, self.task_data)
        self.assertEqual(task, None)
Exemplo n.º 5
0
    def test_use(self):
        with self.check_delta(
                lambda: game_tt_api.energy_balance(self.account_1.id),
                self.CARD.effect.modificator):
            result, step, postsave_actions = self.CARD.effect.use(
                **self.use_attributes(storage=self.storage, hero=self.hero))
            time.sleep(0.1)

        self.assertEqual((result, step, postsave_actions),
                         (ComplexChangeTask.RESULT.SUCCESSED,
                          ComplexChangeTask.STEP.SUCCESS, ()))
    def test_full__double_energy(self):
        with self.check_delta(
                lambda: game_tt_api.energy_balance(self.hero.account_id),
                self.hero.preferences.energy_regeneration_type.amount * 2):

            while len(self.hero.actions.actions_list) != 1:
                self.storage.process_turn(continue_steps_if_needed=False)
                turn.increment()

            time.sleep(0.1)

        self.assertTrue(self.action_idl.leader)
        self.assertEqual(self.hero.need_regenerate_energy, False)
        self.assertEqual(self.hero.last_energy_regeneration_at_turn,
                         turn.number() - 1)

        self.storage._test_save()
Exemplo n.º 7
0
    def test_successfull_result(self):
        game_tt_api.debug_clear_service()

        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 = heroes_logic.load_hero(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(heroes_models.HeroPreferences.objects.all().count(),
                         1)
        self.assertEqual(
            heroes_models.HeroPreferences.objects.get(
                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(game_tt_api.energy_balance(account.id),
                         c.INITIAL_ENERGY_AMOUNT)

        self.assertEqual(game_tt_api.energy_balance(account.id),
                         c.INITIAL_ENERGY_AMOUNT)

        timers = tt_api.get_owner_timers(account_id=account.id)

        self.assertEqual(len(timers), 1)