コード例 #1
0
ファイル: test_balancer.py プロジェクト: angru/the-tale
    def setUp(self):

        super(BalancerBalancingTests, self).setUp()

        self.battle_1 = self.worker.add_to_arena_queue(self.hero_1.id)
        self.battle_2 = self.worker.add_to_arena_queue(self.hero_2.id)

        self.test_record_1 = QueueRecord(account_id=0, created_at=0, battle_id=0, hero_level=1)
        self.test_record_2 = QueueRecord(account_id=1, created_at=1, battle_id=0, hero_level=4)
コード例 #2
0
    def test_initiate_battle_with_bot__create_battle(self):
        self.hero_1._model.level = 50
        self.hero_1.save()

        result, bot_account_id, bundle_id = register_user('bot_user',
                                                          '*****@*****.**',
                                                          '111111',
                                                          is_bot=True)

        records_to_remove, records_to_exclude = self.worker._initiate_battle_with_bot(
            self.battle_1_record())

        bot_battle = Battle1x1Prototype.get_by_id(
            records_to_exclude[1].battle_id)

        bot_record = QueueRecord(account_id=bot_account_id,
                                 battle_id=bot_battle.id,
                                 created_at=bot_battle.created_at +
                                 datetime.timedelta(seconds=0),
                                 hero_level=1)

        self.assertEqual(records_to_remove, [])
        self.assertEqual(records_to_exclude,
                         [self.battle_1_record(), bot_record])
        self.assertEqual(SupervisorTask.objects.all().count(), 1)

        battle_player = Battle1x1Prototype.get_by_account_id(self.account_1.id)
        battle_bot = Battle1x1Prototype.get_by_account_id(bot_account_id)

        self.assertEqual(battle_player.enemy_id, bot_account_id)
        self.assertFalse(battle_player.calculate_rating)
        self.assertEqual(battle_bot.enemy_id, self.account_1.id)
        self.assertFalse(battle_bot.calculate_rating)
コード例 #3
0
    def test_initiate_battle_with_bot__create_battle(self):
        self.hero_1.level = 50
        heroes_logic.save_hero(self.hero_1)

        bot_account = self.accounts_factory.create_account(is_bot=True)

        records_to_remove, records_to_exclude = self.worker._initiate_battle_with_bot(
            self.battle_1_record())

        bot_battle = Battle1x1Prototype.get_by_id(
            records_to_exclude[1].battle_id)

        bot_record = QueueRecord(account_id=bot_account.id,
                                 battle_id=bot_battle.id,
                                 created_at=bot_battle.created_at +
                                 datetime.timedelta(seconds=0),
                                 hero_level=1)

        self.assertEqual(records_to_remove, [])
        self.assertEqual(records_to_exclude,
                         [self.battle_1_record(), bot_record])
        self.assertEqual(SupervisorTask.objects.all().count(), 1)

        battle_player = Battle1x1Prototype.get_by_account_id(self.account_1.id)
        battle_bot = Battle1x1Prototype.get_by_account_id(bot_account.id)

        self.assertEqual(battle_player.enemy_id, bot_account.id)
        self.assertFalse(battle_player.calculate_rating)
        self.assertEqual(battle_bot.enemy_id, self.account_1.id)
        self.assertFalse(battle_bot.calculate_rating)
コード例 #4
0
ファイル: test_balancer.py プロジェクト: angru/the-tale
 def test_process_add_to_arena_queue(self):
     battle = self.worker.add_to_arena_queue(self.hero_1.id)
     self.assertEqual(self.worker.add_to_arena_queue(self.hero_1.id), None)
     self.assertEqual(len(self.worker.arena_queue), 1)
     self.assertEqual(self.worker.arena_queue.values()[0], QueueRecord(account_id=self.account_1.id,
                                                                       battle_id=battle.id,
                                                                       created_at=battle.created_at,
                                                                       hero_level=self.hero_1.level))
コード例 #5
0
ファイル: test_balancer.py プロジェクト: angru/the-tale
    def test_process_add_to_arena_queue__battle_exists_in_waiting_state(self):
        battle = self.worker.add_to_arena_queue(self.hero_1.id)

        self.worker.arena_queue.clear()

        self.assertEqual(self.worker.add_to_arena_queue(self.hero_1.id).id, battle.id)
        self.assertEqual(len(self.worker.arena_queue), 1)
        self.assertEqual(self.worker.arena_queue.values()[0], QueueRecord(account_id=self.account_1.id,
                                                                          battle_id=battle.id,
                                                                          created_at=battle.created_at,
                                                                          hero_level=self.hero_1.level))
コード例 #6
0
 def battle_2_record(self, created_at_delta=datetime.timedelta(seconds=0)):
     return QueueRecord(account_id=self.account_2.id,
                        battle_id=self.battle_2.id,
                        created_at=self.battle_2.created_at +
                        created_at_delta,
                        hero_level=self.hero_2.level)