Exemplo n.º 1
0
    def quest_test_method(self):

        # defends from first quest rule
        self.hero.statistics.change_quests_done(1)
        heroes_logic.save_hero(self.hero)

        current_time = TimePrototype.get_current_time()

        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 = ITEMS_OF_EXPENDITURE.INSTANT_HEAL

            self.storage.process_turn()
            current_time.increment_turn()

        # 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)
Exemplo n.º 2
0
    def setUp(self):
        super(QuestsTestBase, self).setUp()
        self.p1, self.p2, self.p3 = create_test_map()

        # add more persons, to lower conflicts
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p3)
        places_logic.add_person_to_place(self.p3)

        account = self.accounts_factory.create_account(is_fast=True)

        self.storage = LogicStorage()
        self.storage.load_account_data(account)
        self.hero = self.storage.accounts_to_heroes[account.id]
        self.action_idl = self.hero.actions.current_action

        self.hero.money += 1
        self.hero.preferences.set_mob(mobs_storage.all()[0])
        self.hero.preferences.set_place(self.p1)
        self.hero.preferences.set_friend(self.p1.persons[0])
        self.hero.preferences.set_enemy(self.p2.persons[0])
        self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE)
        self.hero.position.set_place(self.p3)
        heroes_logic.save_hero(self.hero)

        self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY)
        places_logic.save_place(self.p2)

        self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH
        persons_logic.save_person(self.p1.persons[0])
Exemplo n.º 3
0
    def setUp(self):
        super(QuestsTestBase, self).setUp()
        self.p1, self.p2, self.p3 = create_test_map()

        # add more persons, to lower conflicts
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p3)
        places_logic.add_person_to_place(self.p3)

        persons_logic.sync_social_connections()

        result, account_id, bundle_id = register_user('test_user')

        self.storage = LogicStorage()
        self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
        self.hero = self.storage.accounts_to_heroes[account_id]
        self.action_idl = self.hero.actions.current_action

        self.hero.money += 1
        self.hero.preferences.set_mob(mobs_storage.all()[0])
        self.hero.preferences.set_place(self.p1)
        self.hero.preferences.set_friend(self.p1.persons[0])
        self.hero.preferences.set_enemy(self.p2.persons[0])
        self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE)
        self.hero.position.set_place(self.p3)
        heroes_logic.save_hero(self.hero)

        self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY)
        places_logic.save_place(self.p2)

        self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH
        persons_logic.save_person(self.p1.persons[0])
Exemplo n.º 4
0
 def test_height_level_battle(self):
     self.hero_2.level = 100
     heroes_logic.save_hero(self.hero_2)
     self.pvp_create_battle(self.account_2, None, BATTLE_1X1_STATE.WAITING)
     self.check_html_ok(self.client.get(reverse('game:pvp:calls')), texts=[('pgf-no-calls-message', 0),
                                                                           ('pgf-no-current-battles-message', 1),
                                                                           ('pgf-can-not-accept-call', 1)])
Exemplo n.º 5
0
    def test_process_energy_discount__no_energy(self):
        self.hero.energy = ABILITY_TYPE.HELP.cost - 2
        self.hero.energy_bonus = 0
        heroes_logic.save_hero(self.hero)

        self.assertFalse(
            self.ability.check_hero_conditions(self.hero, self.task_data))
Exemplo n.º 6
0
    def test_initiate_battle_with_bot__create_battle(self):
        self.hero_1.level = 50
        heroes_logic.save_hero(self.hero_1)

        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)
Exemplo n.º 7
0
    def setUp(self):
        super(QuestsTestBase, self).setUp()
        self.p1, self.p2, self.p3 = create_test_map()

        # add more persons, to lower conflicts
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p3)
        places_logic.add_person_to_place(self.p3)

        persons_logic.sync_social_connections()

        result, account_id, bundle_id = register_user('test_user')

        self.storage = LogicStorage()
        self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
        self.hero = self.storage.accounts_to_heroes[account_id]
        self.action_idl = self.hero.actions.current_action

        self.hero.money += 1
        self.hero.preferences.set_mob(mobs_storage.all()[0])
        self.hero.preferences.set_place(self.p1)
        self.hero.preferences.set_friend(self.p1.persons[0])
        self.hero.preferences.set_enemy(self.p2.persons[0])
        self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE)
        self.hero.position.set_place(self.p3)
        heroes_logic.save_hero(self.hero)

        self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY)
        places_logic.save_place(self.p2)

        self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH
        persons_logic.save_person(self.p1.persons[0])
Exemplo n.º 8
0
    def test_process_bonus_energy(self):
        self.hero.energy = 0
        self.hero.add_energy_bonus(100)
        heroes_logic.save_hero(self.hero)

        self.assertTrue(
            self.ability.check_hero_conditions(self.hero, self.task_data))
Exemplo n.º 9
0
    def test_buying_artifact_without_change(self):
        while not self.hero.next_spending.is_BUYING_ARTIFACT:
            self.hero.switch_spending()

        money = self.hero.spend_amount

        self.assertEqual(self.hero.statistics.money_spend, 0)
        self.assertEqual(self.hero.statistics.money_spend_for_artifacts, 0)
        self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 0)

        # set prefered slot to guaranty that empty slot will be choosen
        self.assertEqual(self.hero.equipment.get(heroes_relations.EQUIPMENT_SLOT.AMULET), None)
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.EQUIPMENT_SLOT, heroes_relations.EQUIPMENT_SLOT.AMULET)

        artifacts_logic.create_random_artifact_record('test_amulet', type=artifacts_relations.ARTIFACT_TYPE.AMULET)

        heroes_logic.save_hero(self.hero)

        # buy artifact
        self.hero.money = money

        self.storage.process_turn()
        self.assertEqual(self.hero.money, 0)
        self.assertEqual(len(list(self.hero.bag.items())), 0)

        self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money)
        self.assertEqual(self.hero.statistics.money_spend_for_artifacts, money - self.hero.money)
        self.assertEqual(self.hero.statistics.artifacts_had, 1)

        self.assertNotEqual(self.hero.equipment.get(heroes_relations.EQUIPMENT_SLOT.AMULET), None)

        self.storage._test_save()
Exemplo n.º 10
0
    def setUp(self):
        super(TestVoteRequests, self).setUp()

        self.account2.prolong_premium(30)
        self.account2.save()

        self.hero = heroes_logic.load_hero(account_id=self.account2.id)
        self.hero.places_history.add_place(self.place1.id)
        self.hero.places_history.add_place(self.place2.id)
        self.hero.places_history.add_place(self.place3.id)

        heroes_logic.save_hero(self.hero)

        new_name = names.generator().get_test_name('new-name')

        data = linguistics_helpers.get_word_post_data(new_name, prefix='name')
        data.update({'caption': 'bill-caption',
                     'rationale': 'bill-rationale',
                     'chronicle_on_accepted': 'chronicle-on-accepted',
                     'place': self.place1.id})

        self.client.post(reverse('game:bills:create') + ('?bill_type=%s' % PlaceRenaming.type.value), data)
        self.bill = BillPrototype(Bill.objects.all()[0])

        self.request_logout()
        self.request_login(self.account2.email)
Exemplo n.º 11
0
    def test_can_not_vote(self):
        tt_api_impacts.debug_clear_service()

        heroes_logic.save_hero(self.hero)

        self.check_ajax_error(self.client.post(url('game:bills:vote', self.bill.id, type=VOTE_TYPE.FOR.value), {}), 'bills.vote.can_not_vote')
        self.check_bill_votes(self.bill.id, 1, 0)
Exemplo n.º 12
0
    def test_buying_artifact_without_change(self):
        while not self.hero.next_spending.is_BUYING_ARTIFACT:
            self.hero.switch_spending()

        money = self.hero.spend_amount

        self.assertEqual(self.hero.statistics.money_spend, 0)
        self.assertEqual(self.hero.statistics.money_spend_for_artifacts, 0)
        self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 0)

        #unequip all arefact
        self.hero.equipment._remove_all()
        heroes_logic.save_hero(self.hero)

        #buy artifact
        self.hero.money = money

        self.storage.process_turn()
        self.assertEqual(self.hero.money, 0)
        self.assertEqual(len(self.hero.bag.items()), 0)

        self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money)
        self.assertEqual(self.hero.statistics.money_spend_for_artifacts, money - self.hero.money)
        self.assertEqual(self.hero.statistics.artifacts_had, 1)
        self.storage._test_save()
Exemplo n.º 13
0
    def setUp(self):
        super(QuestsTestBase, self).setUp()
        self.p1, self.p2, self.p3 = create_test_map()

        # add more persons, to lower conflicts
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p3)
        places_logic.add_person_to_place(self.p3)

        account = self.accounts_factory.create_account(is_fast=True)

        self.storage = LogicStorage()
        self.storage.load_account_data(account)
        self.hero = self.storage.accounts_to_heroes[account.id]
        self.action_idl = self.hero.actions.current_action

        self.hero.money += 1
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.MOB, mobs_storage.mobs.all()[0])
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.PLACE, self.p1)
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.FRIEND, self.p1.persons[0])
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.ENEMY, self.p2.persons[0])
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.EQUIPMENT_SLOT, heroes_relations.EQUIPMENT_SLOT.PLATE)
        self.hero.position.set_place(self.p3)
        heroes_logic.save_hero(self.hero)

        self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY)
        places_logic.save_place(self.p2)

        self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH
        persons_logic.save_person(self.p1.persons[0])
Exemplo n.º 14
0
    def test_add_achievements__all_accounts(self):

        GiveAchievementTaskPrototype.create(
            account_id=None, achievement_id=self.achievement_3.id)

        account_achievements_2 = AccountAchievementsPrototype.get_by_account_id(
            self.account_2.id)

        self.assertFalse(
            self.account_achievements_1.has_achievement(self.achievement_3))
        self.assertFalse(
            account_achievements_2.has_achievement(self.achievement_3))
        hero = heroes_logic.load_hero(account_id=self.account_1.id)
        hero.statistics.change_pve_deaths(self.achievement_3.barrier)
        heroes_logic.save_hero(hero)

        with self.check_not_changed(MessagePrototype._db_count):
            self.worker.add_achievements()

        self.account_achievements_1.reload()
        account_achievements_2.reload()

        self.assertTrue(
            self.account_achievements_1.has_achievement(self.achievement_3))
        self.assertFalse(
            account_achievements_2.has_achievement(self.achievement_3))

        self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
Exemplo n.º 15
0
 def test_banned(self):
     self.hero.ban_state_end_at = datetime.datetime.now() + datetime.timedelta(days=1)
     heroes_logic.save_hero(self.hero)
     self.assertEqual(
         self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR
     )
     self.assertEqual(self.task.state, ComplexChangeTask.STATE.BANNED)
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    def test_is_old(self):
        self.assertFalse(form_game_info(self.account_1, is_own=True)['account']['is_old'])

        turn.set(666)
        self.assertTrue(form_game_info(self.account_1, is_own=True)['account']['is_old'])

        heroes_logic.save_hero(heroes_logic.load_hero(account_id=self.account_1.id))
        self.assertFalse(form_game_info(self.account_1, is_own=True)['account']['is_old'])
Exemplo n.º 18
0
    def test_has_cards(self):
        self.hero.cards.add_card(self.card)
        heroes_logic.save_hero(self.hero)

        self.request_login(self.account.email)
        self.check_html_ok(
            self.request_ajax_html(
                url('game:cards:use-dialog', card=self.card.uid)))
Exemplo n.º 19
0
    def test_is_old__not_own_hero(self):
        self.assertFalse(form_game_info(self.account_1, is_own=False)['account']['is_old'])

        TimePrototype(turn_number=666).save()
        self.assertTrue(form_game_info(self.account_1, is_own=False)['account']['is_old'])

        heroes_logic.save_hero(heroes_logic.load_hero(account_id=self.account_1.id))
        self.assertFalse(form_game_info(self.account_1, is_own=False)['account']['is_old'])
Exemplo n.º 20
0
    def test_is_old__not_own_hero(self):
        self.assertFalse(form_game_info(self.account_1, is_own=False)['account']['is_old'])

        TimePrototype(turn_number=666).save()
        self.assertTrue(form_game_info(self.account_1, is_own=False)['account']['is_old'])

        heroes_logic.save_hero(heroes_logic.load_hero(account_id=self.account_1.id))
        self.assertFalse(form_game_info(self.account_1, is_own=False)['account']['is_old'])
Exemplo n.º 21
0
 def test_banned(self):
     self.hero.ban_state_end_at = datetime.datetime.now(
     ) + datetime.timedelta(days=1)
     heroes_logic.save_hero(self.hero)
     self.assertEqual(
         self.task.process(FakePostpondTaskPrototype(), self.storage),
         POSTPONED_TASK_LOGIC_RESULT.ERROR)
     self.assertEqual(self.task.state, ComplexChangeTask.STATE.BANNED)
Exemplo n.º 22
0
 def test_low_level_battle(self):
     self.hero_1.level = 100
     heroes_logic.save_hero(self.hero_1)
     self.pvp_create_battle(self.account_2, None, BATTLE_1X1_STATE.WAITING)
     self.check_html_ok(
         self.client.get(reverse("game:pvp:calls")),
         texts=[("pgf-no-calls-message", 0), ("pgf-no-current-battles-message", 1), ("pgf-can-not-accept-call", 1)],
     )
Exemplo n.º 23
0
    def setUp(self):
        super(TestShowRequests, self).setUp()

        self.hero = heroes_logic.load_hero(account_id=self.account2.id)
        self.hero.places_history.add_place(self.place1.id)
        self.hero.places_history.add_place(self.place2.id)
        self.hero.places_history.add_place(self.place3.id)
        heroes_logic.save_hero(self.hero)
Exemplo n.º 24
0
 def test_process_no_energy(self):
     self.hero.energy = 0
     self.hero.energy_bonus = 0
     heroes_logic.save_hero(self.hero)
     self.assertEqual(
         self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.ERROR
     )
     self.assertEqual(self.task.state, ComplexChangeTask.STATE.HERO_CONDITIONS_NOT_PASSED)
Exemplo n.º 25
0
    def test_form_invalid(self):
        self.request_login(self.account.email)

        self.hero.cards.add_card(self.card)
        heroes_logic.save_hero(self.hero)

        self.check_ajax_error(self.post_ajax_json(logic.use_card_url(self.card.uid),
                                                  self.post_data(self.card.uid, place_id=666, building_id=666, person_id=666)), 'form_errors')
Exemplo n.º 26
0
    def test_process_energy(self):
        self.hero.energy = self.hero.energy_maximum
        heroes_logic.save_hero(self.hero)

        self.assertTrue(self.ability.check_hero_conditions(self.hero, self.task_data))

        self.ability.hero_actions(self.hero, self.task_data)

        self.assertTrue(self.hero.energy < self.hero.energy_maximum)
Exemplo n.º 27
0
def message_to_hero(hero):
    text = MESSAGES[(hero.gender, hero.race)]

    message = MessageSurrogate.create(key=None, externals={}, position=hero.position.get_description())
    message._message = text

    hero.push_message(message, diary=True, journal=False)

    save_hero(hero)
Exemplo n.º 28
0
    def test_can_not_vote(self):
        self.hero.places_history._reset()
        heroes_logic.save_hero(self.hero)

        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.create_bills(1, self.account2, 'Caption-a1-%d', 'rationale-a1-%d', bill_data)
        bill = Bill.objects.all()[0]

        self.check_html_ok(self.request_html(reverse('game:bills:show', args=[bill.id])), texts=(('pgf-can-not-vote-message', 1),))
Exemplo n.º 29
0
 def test_process_no_energy(self):
     self.hero.energy = 0
     self.hero.energy_bonus = 0
     heroes_logic.save_hero(self.hero)
     self.assertEqual(
         self.task.process(FakePostpondTaskPrototype(), self.storage),
         POSTPONED_TASK_LOGIC_RESULT.ERROR)
     self.assertEqual(self.task.state,
                      ComplexChangeTask.STATE.HERO_CONDITIONS_NOT_PASSED)
Exemplo n.º 30
0
    def test_process_energy(self):
        self.hero.energy = self.hero.energy_maximum
        heroes_logic.save_hero(self.hero)

        self.assertTrue(
            self.ability.check_hero_conditions(self.hero, self.task_data))

        self.ability.hero_actions(self.hero, self.task_data)

        self.assertTrue(self.hero.energy < self.hero.energy_maximum)
Exemplo n.º 31
0
    def test_process_energy_discount__limit_1(self):
        self.hero.energy = 2
        self.hero.energy_bonus = 0
        heroes_logic.save_hero(self.hero)

        self.assertTrue(self.ability.check_hero_conditions(self.hero, self.task_data))

        self.ability.hero_actions(self.hero, self.task_data)

        self.assertEqual(self.hero.energy, 1)
Exemplo n.º 32
0
 def test_fast_user(self):
     self.account_1.is_fast = True
     self.account_1.save()
     self.hero_1.is_fast = True
     heroes_logic.save_hero(self.hero_1)
     self.check_html_ok(self.client.get(reverse('game:pvp:calls')), texts=[('common.fast_account', 0),
                                                                           ('pgf-level-restrictions-message', 0),
                                                                           ('pgf-unlogined-message', 0),
                                                                           ('pgf-no-current-battles-message', 1),
                                                                           ('pgf-fast-account-message', 1)])
Exemplo n.º 33
0
    def test_process_arena_pvp_1x1(self):
        task = SupervisorTaskPrototype.create_arena_pvp_1x1(
            self.account_1, self.account_2)

        task.capture_member(self.account_1.id)
        task.capture_member(self.account_2.id)

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

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

        self.assertEqual(
            Battle1x1.objects.filter(
                state=BATTLE_1X1_STATE.PREPAIRING).count(), 2)
        self.assertEqual(
            Battle1x1.objects.filter(
                state=BATTLE_1X1_STATE.PROCESSING).count(), 0)

        old_hero = heroes_logic.load_hero(account_id=self.account_1.id)
        old_hero.health = 1
        heroes_logic.save_hero(old_hero)

        task.process(bundle_id=666)

        new_hero = heroes_logic.load_hero(account_id=self.account_1.id)
        new_hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.assertEqual(new_hero.actions.current_action.bundle_id,
                         new_hero_2.actions.current_action.bundle_id)
        self.assertNotEqual(new_hero.actions.actions_list[0].bundle_id,
                            new_hero.actions.actions_list[1].bundle_id)
        self.assertNotEqual(new_hero_2.actions.actions_list[0].bundle_id,
                            new_hero_2.actions.actions_list[1].bundle_id)

        self.assertNotEqual(old_hero, new_hero)
        self.assertTrue(old_hero.actions.number < new_hero.actions.number)
        self.assertEqual(new_hero.health, new_hero.max_health)

        self.assertEqual(new_hero.actions.number, 2)
        self.assertEqual(new_hero_2.actions.number, 2)

        self.assertEqual(
            new_hero.actions.current_action.meta_action.serialize(),
            new_hero_2.actions.current_action.meta_action.serialize())

        self.assertEqual(
            Battle1x1.objects.filter(
                state=BATTLE_1X1_STATE.PREPAIRING).count(), 0)
        self.assertEqual(
            Battle1x1.objects.filter(
                state=BATTLE_1X1_STATE.PROCESSING).count(), 2)
Exemplo n.º 34
0
    def test_help_choice_heal_not_in_choices_for_dead_hero(self):

        self.hero.health = 1
        heroes_logic.save_hero(self.hero)

        self.assertTrue(HELP_CHOICES.HEAL in self.action_idl.help_choices)

        self.hero.kill()
        heroes_logic.save_hero(self.hero)

        self.assertFalse(HELP_CHOICES.HEAL in self.action_idl.help_choices)
Exemplo n.º 35
0
def message_to_hero(hero):
    text = MESSAGES[(hero.gender, hero.race)]

    message = MessageSurrogate.create(key=None,
                                      externals={},
                                      position=hero.position.get_description())
    message._message = text

    hero.push_message(message, diary=True, journal=False)

    save_hero(hero)
Exemplo n.º 36
0
    def test_help_choice_heal_not_in_choices_for_dead_hero(self):

        self.hero.health = 1
        heroes_logic.save_hero(self.hero)

        self.assertTrue(HELP_CHOICES.HEAL in self.action_idl.help_choices)

        self.hero.kill()
        heroes_logic.save_hero(self.hero)

        self.assertFalse(HELP_CHOICES.HEAL in self.action_idl.help_choices)
Exemplo n.º 37
0
    def test_process_energy_discount__limit_1(self):
        self.hero.energy = 2
        self.hero.energy_bonus = 0
        heroes_logic.save_hero(self.hero)

        self.assertTrue(
            self.ability.check_hero_conditions(self.hero, self.task_data))

        self.ability.hero_actions(self.hero, self.task_data)

        self.assertEqual(self.hero.energy, 1)
Exemplo n.º 38
0
    def test_success(self):
        self.request_login(self.account.email)

        self.hero.cards.add_card(self.card)
        heroes_logic.save_hero(self.hero)

        response = self.post_ajax_json(logic.use_card_url(self.card.uid), self.post_data(self.card.uid))
        task = PostponedTaskPrototype._db_get_object(0)

        self.check_ajax_processing(response, task.status_url)

        task.remove()
Exemplo n.º 39
0
    def test_success(self):
        self.request_login(self.account.email)

        self.hero.cards.add_card(self.card)
        heroes_logic.save_hero(self.hero)

        response = self.post_ajax_json(logic.use_card_url(self.card.uid), self.post_data(self.card.uid))
        task = PostponedTaskPrototype._db_get_object(0)

        self.check_ajax_processing(response, task.status_url)

        task.remove()
Exemplo n.º 40
0
    def test_can_not_vote(self):
        tt_api_impacts.debug_clear_service()

        heroes_logic.save_hero(self.hero)

        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.create_bills(1, self.account2, 'Caption-a1-%d', bill_data)
        bill = Bill.objects.all()[0]

        self.account1.prolong_premium(30)
        self.account1.save()

        self.check_html_ok(self.request_html(reverse('game:bills:show', args=[bill.id])), texts=(('pgf-can-not-vote-message', 1),))
Exemplo n.º 41
0
    def test_show__places_history(self):
        texts = [(self.place1.name, 1), (self.place2.name, 1),
                 (self.place3.name, 0), ('pgf-no-common-places-message', 0)]

        hero = heroes_logic.load_hero(account_id=self.account_1.id)
        hero.places_history.add_place(self.place1.id)
        hero.places_history.add_place(self.place2.id)
        hero.places_history.add_place(self.place1.id)
        heroes_logic.save_hero(hero)

        self.check_html_ok(self.request_html(
            reverse('accounts:show', args=[self.account_1.id])),
                           texts=texts)
Exemplo n.º 42
0
    def test_form_invalid(self):
        self.request_login(self.account.email)

        self.hero.cards.add_card(self.card)
        heroes_logic.save_hero(self.hero)

        self.check_ajax_error(
            self.post_ajax_json(
                logic.use_card_url(self.card.uid),
                self.post_data(self.card.uid, place_id=666, building_id=666, person_id=666),
            ),
            "form_errors",
        )
Exemplo n.º 43
0
    def test_show__places_history(self):
        texts = [(self.place1.name, 1),
                 (self.place2.name, 1),
                 (self.place3.name, 0),
                 ('pgf-no-common-places-message', 0)]

        hero = heroes_logic.load_hero(account_id=self.account_1.id)
        hero.places_history.add_place(self.place1.id)
        hero.places_history.add_place(self.place2.id)
        hero.places_history.add_place(self.place1.id)
        heroes_logic.save_hero(hero)

        self.check_html_ok(self.request_html(reverse('accounts:show', args=[self.account_1.id])), texts=texts)
Exemplo n.º 44
0
    def test_process_energy_discount__no_less_1(self):
        self.hero.energy = 0
        self.hero.energy_bonus = 0
        heroes_logic.save_hero(self.hero)

        self.assertFalse(
            self.ability.check_hero_conditions(self.hero, self.task_data))

        self.hero.energy = 1
        self.hero.energy_bonus = 0
        heroes_logic.save_hero(self.hero)

        self.assertTrue(
            self.ability.check_hero_conditions(self.hero, self.task_data))
Exemplo n.º 45
0
    def test_created(self):
        self.request_login(self.account.email)

        card_1 = objects.Card(relations.CARD_TYPE.ADD_GOLD_COMMON)
        card_2 = objects.Card(relations.CARD_TYPE.ADD_GOLD_COMMON)

        self.hero.cards.add_card(card_1)
        self.hero.cards.add_card(card_2)

        heroes_logic.save_hero(self.hero)

        with self.check_delta(PostponedTaskPrototype._db_count, 1):
            response = self.post_ajax_json(logic.combine_cards_url((card_1.uid, card_2.uid)))

        task = PostponedTaskPrototype._db_get_object(0)

        self.check_ajax_processing(response, task.status_url)
Exemplo n.º 46
0
    def test_initiate_battle_without_rating_by_level(self):

        self.assertEqual(SupervisorTask.objects.all().count(), 0)

        self.hero_1.level = 100
        heroes_logic.save_hero(self.hero_1)

        self.worker._initiate_battle(self.battle_1_record(), self.battle_2_record())

        battle_1 = Battle1x1Prototype.get_by_id(self.battle_1.id)
        battle_2 = Battle1x1Prototype.get_by_id(self.battle_2.id)

        self.assertEqual(battle_1.enemy_id, self.account_2.id)
        self.assertFalse(battle_1.calculate_rating)
        self.assertEqual(battle_2.enemy_id, self.account_1.id)
        self.assertFalse(battle_2.calculate_rating)

        self.assertEqual(SupervisorTask.objects.all().count(), 1)
Exemplo n.º 47
0
    def test_is_old__pvp(self):
        self.pvp_create_battle(self.account_1, self.account_2, BATTLE_1X1_STATE.PROCESSING)
        self.pvp_create_battle(self.account_2, self.account_1, BATTLE_1X1_STATE.PROCESSING)

        hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)
        hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.assertFalse(form_game_info(self.account_1)['account']['is_old'])
        self.assertFalse(form_game_info(self.account_1)['enemy']['is_old'])

        TimePrototype(turn_number=666).save()
        self.assertTrue(form_game_info(self.account_1)['account']['is_old'])
        self.assertTrue(form_game_info(self.account_1)['enemy']['is_old'])

        heroes_logic.save_hero(hero_1)
        heroes_logic.save_hero(hero_2)

        self.assertFalse(form_game_info(self.account_1)['account']['is_old'])
        self.assertFalse(form_game_info(self.account_1)['enemy']['is_old'])
Exemplo n.º 48
0
    def test_process_arena_pvp_1x1(self):
        task = SupervisorTaskPrototype.create_arena_pvp_1x1(self.account_1, self.account_2)

        task.capture_member(self.account_1.id)
        task.capture_member(self.account_2.id)

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

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

        self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PREPAIRING).count(), 2)
        self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PROCESSING).count(), 0)

        old_hero = heroes_logic.load_hero(account_id=self.account_1.id)
        old_hero.health = 1
        heroes_logic.save_hero(old_hero)

        task.process(bundle_id=666)

        new_hero = heroes_logic.load_hero(account_id=self.account_1.id)
        new_hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.assertEqual(new_hero.actions.current_action.bundle_id, new_hero_2.actions.current_action.bundle_id)
        self.assertNotEqual(new_hero.actions.actions_list[0].bundle_id, new_hero.actions.actions_list[1].bundle_id)
        self.assertNotEqual(new_hero_2.actions.actions_list[0].bundle_id, new_hero_2.actions.actions_list[1].bundle_id)

        self.assertNotEqual(old_hero, new_hero)
        self.assertTrue(old_hero.actions.number < new_hero.actions.number)
        self.assertEqual(new_hero.health, new_hero.max_health)

        self.assertEqual(new_hero.actions.number, 2)
        self.assertEqual(new_hero_2.actions.number, 2)

        self.assertEqual(new_hero.actions.current_action.meta_action.serialize(),
                         new_hero_2.actions.current_action.meta_action.serialize())

        self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PREPAIRING).count(), 0)
        self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PROCESSING).count(), 2)
Exemplo n.º 49
0
    def test_game_info_data_hidding(self):
        '''
        player hero always must show actual data
        enemy hero always must show data on statrt of the turn
        '''
        self.pvp_create_battle(self.account_1, self.account_2, BATTLE_1X1_STATE.PROCESSING)
        self.pvp_create_battle(self.account_2, self.account_1, BATTLE_1X1_STATE.PROCESSING)

        hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)
        hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        hero_1.pvp.set_energy(1)
        heroes_logic.save_hero(hero_1)

        hero_2.pvp.set_energy(2)
        heroes_logic.save_hero(hero_2)

        data = form_game_info(self.account_1, is_own=True)

        self.assertEqual(data['account']['hero']['pvp']['energy'], 1)
        self.assertEqual(data['enemy']['hero']['pvp']['energy'], 0)

        hero_2.pvp.store_turn_data()
        heroes_logic.save_hero(hero_2)

        data = form_game_info(self.account_1, is_own=True)

        self.assertEqual(data['enemy']['hero']['pvp']['energy'], 2)
Exemplo n.º 50
0
    def test_register_accounts_on_initialization__multiple_accounts_bandles(self):
        account_3 = self.accounts_factory.create_account()
        account_4 = self.accounts_factory.create_account()
        account_5 = self.accounts_factory.create_account()
        account_6 = self.accounts_factory.create_account()

        hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)
        hero_3 = heroes_logic.load_hero(account_id=account_3.id)
        hero_4 = heroes_logic.load_hero(account_id=account_4.id)
        hero_6 = heroes_logic.load_hero(account_id=account_6.id)

        hero_3.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id
        hero_3.actions.updated = True
        heroes_logic.save_hero(hero_3)

        hero_4.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id
        hero_4.actions.updated = True
        heroes_logic.save_hero(hero_4)

        hero_6.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id
        hero_6.actions.updated = True
        heroes_logic.save_hero(hero_6)

        self.worker.process_initialize()

        self.assertEqual(self.worker.accounts_owners, {self.account_1.id: 'game_logic_1',
                                                       self.account_2.id: 'game_logic_2',
                                                       account_3.id: 'game_logic_2',
                                                       account_4.id: 'game_logic_2',
                                                       account_5.id: 'game_logic_1',
                                                       account_6.id: 'game_logic_2'})
        self.assertEqual(self.worker.logic_accounts_number, {'game_logic_1': 2, 'game_logic_2': 4})
Exemplo n.º 51
0
    def test_add_achievements__all_accounts(self):

        GiveAchievementTaskPrototype.create(account_id=None, achievement_id=self.achievement_3.id)

        account_achievements_2 = AccountAchievementsPrototype.get_by_account_id(self.account_2.id)

        self.assertFalse(self.account_achievements_1.has_achievement(self.achievement_3))
        self.assertFalse(account_achievements_2.has_achievement(self.achievement_3))
        hero = heroes_logic.load_hero(account_id=self.account_1.id)
        hero.statistics.change_pve_deaths(self.achievement_3.barrier)
        heroes_logic.save_hero(hero)

        with self.check_not_changed(MessagePrototype._db_count):
            self.worker.add_achievements()

        self.account_achievements_1.reload()
        account_achievements_2.reload()

        self.assertTrue(self.account_achievements_1.has_achievement(self.achievement_3))
        self.assertFalse(account_achievements_2.has_achievement(self.achievement_3))

        self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
Exemplo n.º 52
0
    def test_sharpening_artifact_with_hero_preferences(self):
        while not self.hero.next_spending.is_SHARPENING_ARTIFACT:
            self.hero.switch_spending()

        self.hero.preferences.set_equipment_slot(heroes_relations.EQUIPMENT_SLOT.PLATE)
        self.hero.level = 666 # enshure that equipment power will be less than max allowerd _power
        heroes_logic.save_hero(self.hero)

        money = self.hero.spend_amount

        old_power = self.hero.power.clone()
        old_plate_power = self.hero.equipment.get(heroes_relations.EQUIPMENT_SLOT.PLATE).power.clone()

        self.hero.money = money
        self.storage.process_turn()
        self.assertEqual(self.hero.money, 0)
        self.assertEqual(old_power.total() + 1, self.hero.power.total())
        self.assertEqual(old_plate_power.total() + 1, self.hero.equipment.get(heroes_relations.EQUIPMENT_SLOT.PLATE).power.total())

        self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money)
        self.assertEqual(self.hero.statistics.money_spend_for_sharpening, money - self.hero.money)
        self.storage._test_save()
Exemplo n.º 53
0
    def test_buying_artifact_with_hero_preferences(self):
        while not self.hero.next_spending.is_BUYING_ARTIFACT:
            self.hero.switch_spending()

        money = self.hero.spend_amount

        self.assertEqual(self.hero.statistics.money_spend, 0)
        self.assertEqual(self.hero.statistics.money_spend_for_artifacts, 0)
        self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 0)

        #unequip all arefact
        self.hero.equipment._remove_all()
        # self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE)
        heroes_logic.save_hero(self.hero)

        #buy artifact
        self.hero.money = money
        self.storage.process_turn()
        self.assertTrue(self.hero.money < 1)
        self.assertEqual(len(self.hero.bag.items()), 0)

        self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money)
        self.assertEqual(self.hero.statistics.money_spend_for_artifacts, money - self.hero.money)
        self.assertEqual(self.hero.statistics.artifacts_had, 1)