Example #1
0
    def setUp(self):
        super(UsePvPAbilityTests, 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.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(ABILITIES.values())

        self.task = UsePvPAbilityTask(battle_id=self.battle.id,
                                      account_id=self.account_1.id,
                                      ability_id=self.ability.TYPE)
Example #2
0
 def test_wrong_ability_id(self):
     task = UsePvPAbilityTask(battle_id=self.battle.id,
                              account_id=self.account_1.id,
                              ability_id='wrong_ability_id')
     task.process(FakePostpondTaskPrototype(), self.storage)
     self.assertEqual(task.state,
                      USE_PVP_ABILITY_TASK_STATE.WRONG_ABILITY_ID)
    def setUp(self):
        super(UsePvPAbilityTests, 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.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(ABILITIES.values())

        self.task = UsePvPAbilityTask(battle_id=self.battle.id, account_id=self.account_1.id, ability_id=self.ability.TYPE)
Example #4
0
    def setUp(self):
        super(UsePvPAbilityTests, self).setUp()

        self.p1, self.p2, self.p3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(list(ABILITIES.values()))

        self.task = UsePvPAbilityTask(battle_id=self.battle.id, account_id=self.account_1.id, ability_id=self.ability.TYPE)

        self.meta_action_battle = meta_actions.ArenaPvP1x1.create(self.storage, self.hero_1, self.hero_2)
        self.meta_action_battle.set_storage(self.storage)

        actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_1, _bundle_id=self.hero_1.actions.current_action.bundle_id, meta_action=self.meta_action_battle)
        actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_2, _bundle_id=self.hero_1.actions.current_action.bundle_id, meta_action=self.meta_action_battle)
Example #5
0
    def setUp(self):
        super(UsePvPAbilityTests, self).setUp()

        self.p1, self.p2, self.p3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(list(ABILITIES.values()))

        self.task = UsePvPAbilityTask(battle_id=self.battle.id,
                                      account_id=self.account_1.id,
                                      ability_id=self.ability.TYPE)

        self.meta_action_battle = meta_actions.ArenaPvP1x1.create(
            self.storage, self.hero_1, self.hero_2)
        self.meta_action_battle.set_storage(self.storage)

        actions_prototypes.ActionMetaProxyPrototype.create(
            hero=self.hero_1,
            _bundle_id=self.hero_1.actions.current_action.bundle_id,
            meta_action=self.meta_action_battle)
        actions_prototypes.ActionMetaProxyPrototype.create(
            hero=self.hero_2,
            _bundle_id=self.hero_1.actions.current_action.bundle_id,
            meta_action=self.meta_action_battle)
Example #6
0
    def use_ability(self, ability):

        battle = Battle1x1Prototype.get_by_account_id(self.account.id)

        if battle is None or not battle.state.is_PROCESSING:
            return self.json_error(
                'pvp.use_ability.no_battle',
                u'Бой не идёт, вы не можете использовать способность')

        use_ability_task = UsePvPAbilityTask(battle_id=battle.id,
                                             account_id=self.account.id,
                                             ability_id=ability.TYPE)

        task = PostponedTaskPrototype.create(use_ability_task)

        environment.workers.supervisor.cmd_logic_task(self.account.id, task.id)

        return self.json_processing(task.status_url)
Example #7
0
 def test_serialize(self):
     self.assertEqual(
         self.task.serialize(),
         UsePvPAbilityTask.deserialize(self.task.serialize()).serialize())
Example #8
0
class UsePvPAbilityTests(testcase.TestCase):
    def setUp(self):
        super(UsePvPAbilityTests, self).setUp()

        self.p1, self.p2, self.p3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(list(ABILITIES.values()))

        self.task = UsePvPAbilityTask(battle_id=self.battle.id,
                                      account_id=self.account_1.id,
                                      ability_id=self.ability.TYPE)

        self.meta_action_battle = meta_actions.ArenaPvP1x1.create(
            self.storage, self.hero_1, self.hero_2)
        self.meta_action_battle.set_storage(self.storage)

        actions_prototypes.ActionMetaProxyPrototype.create(
            hero=self.hero_1,
            _bundle_id=self.hero_1.actions.current_action.bundle_id,
            meta_action=self.meta_action_battle)
        actions_prototypes.ActionMetaProxyPrototype.create(
            hero=self.hero_2,
            _bundle_id=self.hero_1.actions.current_action.bundle_id,
            meta_action=self.meta_action_battle)

    def test_create(self):
        self.assertEqual(self.task.state,
                         USE_PVP_ABILITY_TASK_STATE.UNPROCESSED)
        self.assertEqual(self.task.battle_id, self.battle.id)
        self.assertEqual(self.task.account_id, self.account_1.id)
        self.assertEqual(self.task.ability_id, self.ability.TYPE)

    def test_serialize(self):
        self.assertEqual(
            self.task.serialize(),
            UsePvPAbilityTask.deserialize(self.task.serialize()).serialize())

    def test_process_battle_not_found(self):
        Battle1x1Prototype._db_all().delete()
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state,
                         USE_PVP_ABILITY_TASK_STATE.BATTLE_FINISHED)

    def test_process_hero_not_found(self):
        self.storage.release_account_data(self.account_1.id)
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state,
                         USE_PVP_ABILITY_TASK_STATE.HERO_NOT_FOUND)

    def test_wrong_ability_id(self):
        task = UsePvPAbilityTask(battle_id=self.battle.id,
                                 account_id=self.account_1.id,
                                 ability_id='wrong_ability_id')
        task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(task.state,
                         USE_PVP_ABILITY_TASK_STATE.WRONG_ABILITY_ID)

    def test_no_resources(self):
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.NO_ENERGY)

    def test_process_success(self):
        self.meta_action_battle.hero_1_pvp.set_energy(1)

        old_hero_1_last_message = self.hero_1.journal.messages[-1]
        old_hero_2_last_message = self.hero_2.journal.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.journal.messages[-1])
        self.assertNotEqual(old_hero_2_last_message,
                            self.hero_2.journal.messages[-1])

        self.assertNotEqual(old_hero_1_last_message.ui_info(),
                            self.hero_1.journal.ui_info()[-1])
        self.assertEqual(old_hero_2_last_message.ui_info(),
                         self.hero_2.journal.ui_info()[-1])

        self.assertEqual(self.meta_action_battle.hero_1_pvp.energy, 0)
 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_serialize(self):
     self.assertEqual(self.task.serialize(), UsePvPAbilityTask.deserialize(self.task.serialize()).serialize())
class UsePvPAbilityTests(testcase.TestCase):

    def setUp(self):
        super(UsePvPAbilityTests, 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.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(ABILITIES.values())

        self.task = UsePvPAbilityTask(battle_id=self.battle.id, account_id=self.account_1.id, ability_id=self.ability.TYPE)

    def test_create(self):
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.UNPROCESSED)
        self.assertEqual(self.task.battle_id, self.battle.id)
        self.assertEqual(self.task.account_id, self.account_1.id)
        self.assertEqual(self.task.ability_id, self.ability.TYPE)

    def test_serialize(self):
        self.assertEqual(self.task.serialize(), UsePvPAbilityTask.deserialize(self.task.serialize()).serialize())

    def test_process_battle_not_found(self):
        Battle1x1Prototype._db_all().delete()
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.BATTLE_FINISHED)

    def test_process_hero_not_found(self):
        self.storage.release_account_data(self.account_1.id)
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.HERO_NOT_FOUND)

    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_no_resources(self):
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.NO_ENERGY)

    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][2])
        self.assertEqual(old_hero_2_last_message.ui_info()[-1], self.hero_2.messages.ui_info()[-1][2])

        self.assertEqual(self.hero_1.pvp.energy, 0)
Example #12
0
class UsePvPAbilityTests(testcase.TestCase):

    def setUp(self):
        super(UsePvPAbilityTests, self).setUp()

        self.p1, self.p2, self.p3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(list(ABILITIES.values()))

        self.task = UsePvPAbilityTask(battle_id=self.battle.id, account_id=self.account_1.id, ability_id=self.ability.TYPE)

        self.meta_action_battle = meta_actions.ArenaPvP1x1.create(self.storage, self.hero_1, self.hero_2)
        self.meta_action_battle.set_storage(self.storage)

        actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_1, _bundle_id=self.hero_1.actions.current_action.bundle_id, meta_action=self.meta_action_battle)
        actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_2, _bundle_id=self.hero_1.actions.current_action.bundle_id, meta_action=self.meta_action_battle)


    def test_create(self):
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.UNPROCESSED)
        self.assertEqual(self.task.battle_id, self.battle.id)
        self.assertEqual(self.task.account_id, self.account_1.id)
        self.assertEqual(self.task.ability_id, self.ability.TYPE)

    def test_serialize(self):
        self.assertEqual(self.task.serialize(), UsePvPAbilityTask.deserialize(self.task.serialize()).serialize())

    def test_process_battle_not_found(self):
        Battle1x1Prototype._db_all().delete()
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.BATTLE_FINISHED)

    def test_process_hero_not_found(self):
        self.storage.release_account_data(self.account_1.id)
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.HERO_NOT_FOUND)

    def test_wrong_ability_id(self):
        task = UsePvPAbilityTask(battle_id=self.battle.id, account_id=self.account_1.id, ability_id='wrong_ability_id')
        task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(task.state, USE_PVP_ABILITY_TASK_STATE.WRONG_ABILITY_ID)

    def test_no_resources(self):
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.NO_ENERGY)

    def test_process_success(self):
        self.meta_action_battle.hero_1_pvp.set_energy(1)

        old_hero_1_last_message = self.hero_1.journal.messages[-1]
        old_hero_2_last_message = self.hero_2.journal.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.journal.messages[-1])
        self.assertNotEqual(old_hero_2_last_message, self.hero_2.journal.messages[-1])

        self.assertNotEqual(old_hero_1_last_message.ui_info(), self.hero_1.journal.ui_info()[-1])
        self.assertEqual(old_hero_2_last_message.ui_info(), self.hero_2.journal.ui_info()[-1])

        self.assertEqual(self.meta_action_battle.hero_1_pvp.energy, 0)
Example #13
0
class UsePvPAbilityTests(testcase.TestCase):
    def setUp(self):
        super(UsePvPAbilityTests, 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.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(ABILITIES.values())

        self.task = UsePvPAbilityTask(battle_id=self.battle.id,
                                      account_id=self.account_1.id,
                                      ability_id=self.ability.TYPE)

    def test_create(self):
        self.assertEqual(self.task.state,
                         USE_PVP_ABILITY_TASK_STATE.UNPROCESSED)
        self.assertEqual(self.task.battle_id, self.battle.id)
        self.assertEqual(self.task.account_id, self.account_1.id)
        self.assertEqual(self.task.ability_id, self.ability.TYPE)

    def test_serialize(self):
        self.assertEqual(
            self.task.serialize(),
            UsePvPAbilityTask.deserialize(self.task.serialize()).serialize())

    def test_process_battle_not_found(self):
        Battle1x1Prototype._db_all().delete()
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state,
                         USE_PVP_ABILITY_TASK_STATE.BATTLE_FINISHED)

    def test_process_hero_not_found(self):
        self.storage.release_account_data(self.account_1.id)
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state,
                         USE_PVP_ABILITY_TASK_STATE.HERO_NOT_FOUND)

    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_no_resources(self):
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.NO_ENERGY)

    def test_process_success(self):
        self.hero_1.pvp.set_energy(1)

        old_hero_1_last_message = self.hero_1.journal.messages[-1]
        old_hero_2_last_message = self.hero_2.journal.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.journal.messages[-1])
        self.assertNotEqual(old_hero_2_last_message,
                            self.hero_2.journal.messages[-1])

        self.assertNotEqual(old_hero_1_last_message.ui_info()[-1],
                            self.hero_1.journal.ui_info()[-1][-1])
        self.assertEqual(old_hero_2_last_message.ui_info()[-1],
                         self.hero_2.journal.ui_info()[-1][-1])

        self.assertEqual(self.hero_1.pvp.energy, 0)