def test_load_account_data_with_meta_action(self): bundle_id = 666 meta_action_battle = meta_actions.ArenaPvP1x1.create(self.storage, self.hero_1, self.hero_2) proxy_action_1 = actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_1, _bundle_id=bundle_id, meta_action=meta_action_battle) proxy_action_2 = actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_2, _bundle_id=bundle_id, meta_action=meta_action_battle) self.assertEqual(len(self.storage.meta_actions), 1) self.assertEqual(len(self.storage.meta_actions_to_actions), 1) self.assertEqual(self.storage.meta_actions_to_actions[meta_action_battle.uid], set([LogicStorage.get_action_uid(proxy_action_1), LogicStorage.get_action_uid(proxy_action_2)])) self.storage.save_changed_data() self.assertIs(self.hero_1.actions.current_action.meta_action, self.hero_2.actions.current_action.meta_action) self.assertIs(self.hero_1.actions.current_action.saved_meta_action, self.hero_2.actions.current_action.saved_meta_action) storage = LogicStorage() storage.load_account_data(AccountPrototype.get_by_id(self.account_1.id)) storage.load_account_data(AccountPrototype.get_by_id(self.account_2.id)) self.assertEqual(len(storage.meta_actions), 1) self.assertEqual(len(storage.meta_actions_to_actions), 1) self.assertEqual(storage.meta_actions_to_actions[meta_action_battle.uid], set([LogicStorage.get_action_uid(proxy_action_1), LogicStorage.get_action_uid(proxy_action_2)])) self.assertEqual(storage.bundles_to_accounts, {self.hero_1.actions.current_action.bundle_id: set([self.account_1.id, self.account_2.id])}) hero_1 = storage.accounts_to_heroes[self.account_1.id] hero_2 = storage.accounts_to_heroes[self.account_2.id] self.assertIs(hero_1.actions.current_action.meta_action, hero_2.actions.current_action.meta_action) self.assertIsNot(hero_1.actions.current_action.saved_meta_action, hero_2.actions.current_action.saved_meta_action) self.assertEqual(hero_1.actions.current_action.saved_meta_action.serialize(), hero_2.actions.current_action.saved_meta_action.serialize())
def setUp(self): super(BaseTestRequests, self).setUp() self.place1, self.place2, self.place3 = create_test_map() result, account_id, bundle_id = register_user('test_user1', '*****@*****.**', '111111') self.account1 = AccountPrototype.get_by_id(account_id) self.account1.prolong_premium(30) self.account1._model.created_at -= datetime.timedelta(days=bills_settings.MINIMUM_BILL_OWNER_AGE) self.account1.save() result, account_id, bundle_id = register_user('test_user2', '*****@*****.**', '111111') self.account2 = AccountPrototype.get_by_id(account_id) self.account2.prolong_premium(30) self.account2._model.created_at -= datetime.timedelta(days=bills_settings.MINIMUM_BILL_OWNER_AGE) self.account2.save() self.client = client.Client() self.request_login('*****@*****.**') from the_tale.forum.models import Category, SubCategory forum_category = Category.objects.create(caption='Category-1', slug='category-1') SubCategory.objects.create(caption=bills_settings.FORUM_CATEGORY_UID + '-caption', uid=bills_settings.FORUM_CATEGORY_UID, category=forum_category)
def test_change_credentials__with_referral(self): self.fast_account._model.referral_of = self.account._model self.fast_account.save() self.assertTrue(AccountPrototype.get_by_id(self.fast_account.id).is_fast) with mock.patch("the_tale.game.workers.supervisor.Worker.cmd_update_hero_with_account_data") as fake_cmd: with mock.patch( "the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method" ) as cmd_run_account_method: self.fast_account.change_credentials( new_email="*****@*****.**", new_password=make_password("222222"), new_nick="test_nick" ) self.assertEqual(cmd_run_account_method.call_count, 1) self.assertEqual( cmd_run_account_method.call_args, mock.call( account_id=self.account.id, method_name=AccountPrototype.update_referrals_number.__name__, data={} ), ) self.assertEqual(django_authenticate(nick="test_nick", password="******").id, self.fast_account.id) self.assertFalse(AccountPrototype.get_by_id(self.fast_account.id).is_fast) self.assertEqual(fake_cmd.call_count, 1) self.assertFalse(fake_cmd.call_args[1]["is_fast"])
def test_get_bundles_to_save__without_cache_dump(self): # hero 1 not saved # hero 2 saved by quota # hero 3 does not saved by caching # hero 4 not saved result, account_3_id, bundle_3_id = register_user( 'test_user_3', '*****@*****.**', '111111') result, account_4_id, bundle_4_id = register_user( 'test_user_4', '*****@*****.**', '111111') self.storage.load_account_data( AccountPrototype.get_by_id(account_3_id)) self.storage.load_account_data( AccountPrototype.get_by_id(account_4_id)) hero_3 = self.storage.accounts_to_heroes[account_3_id] hero_4 = self.storage.accounts_to_heroes[account_4_id] self.hero_1._model.saved_at = datetime.datetime.now() self.hero_1.ui_caching_started_at = datetime.datetime.fromtimestamp(0) self.hero_2.ui_caching_started_at = datetime.datetime.fromtimestamp(0) hero_4.ui_caching_started_at = datetime.datetime.fromtimestamp(0) self.assertTrue(self.hero_1.saved_at > self.hero_2.saved_at) self.assertFalse(self.hero_1.is_ui_caching_required) self.assertFalse(self.hero_2.is_ui_caching_required) self.assertTrue(hero_3.is_ui_caching_required) self.assertFalse(hero_4.is_ui_caching_required) self.assertEqual(self.storage._get_bundles_to_save(), set([self.bundle_2_id]))
def setUp(self): super(BaseTestRequests, self).setUp() mobs_storage.sync(force=True) self.place_1, self.place_2, self.place_3 = create_test_map() result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111') self.account_3 = AccountPrototype.get_by_id(account_id) self.client = client.Client() self.request_login('*****@*****.**') group_create = sync_group('create mob', ['mobs.create_mobrecord']) group_add = sync_group('add mob', ['mobs.moderate_mobrecord']) group_create.user_set.add(self.account_2._model) group_add.user_set.add(self.account_3._model)
def setUp(self): super(SayInBattleLogTests, 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.task = SayInBattleLogTask(battle_id=self.battle.id, text=u'some pvp message')
def setUp(self): super(RepairBuildingTests, self).setUp() self.place_1, self.place_2, self.place_3 = 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') 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 = self.storage.accounts_to_heroes[self.account_1.id] self.card = self.CARD() environment.deinitialize() environment.initialize() self.highlevel = environment.workers.highlevel self.highlevel.process_initialize(0, 'highlevel') self.building_1 = BuildingPrototype.create(person=self.place_1.persons[0], utg_name=names.generator.get_test_name('building-1-name')) self.building_2 = BuildingPrototype.create(person=self.place_2.persons[0], utg_name=names.generator.get_test_name('building-1-name')) self.building_1.amortize(c.TURNS_IN_HOUR*24) self.building_2.amortize(c.TURNS_IN_HOUR*24)
def test_load_account_data(self): self.assertEqual(len(self.storage.heroes), 2) self.assertEqual(len(self.storage.accounts_to_heroes), 2) self.assertEqual( self.storage.bundles_to_accounts, { self.hero_1.actions.current_action.bundle_id: set([self.account_1.id]), self.hero_2.actions.current_action.bundle_id: set([self.account_2.id]) }) action_regenerate = actions_prototypes.ActionRegenerateEnergyPrototype.create( hero=self.hero_1) self.assertEqual(self.action_idl_1.storage, self.storage) self.assertEqual(action_regenerate.storage, self.storage) storage = LogicStorage() storage.load_account_data(AccountPrototype.get_by_id( self.account_1.id)) storage.load_account_data(AccountPrototype.get_by_id( self.account_2.id)) self.assertEqual(len(storage.heroes), 2) self.assertEqual(len(storage.accounts_to_heroes), 2) self.assertEqual( storage.bundles_to_accounts, { self.hero_1.actions.current_action.bundle_id: set([self.account_1.id]), self.hero_2.actions.current_action.bundle_id: set([self.account_2.id]) })
def test_initialize_bots__bot_is_first(self): result, account_1_id, bundle_id = register_user('bot', '*****@*****.**', '111111', is_bot=True) result, account_2_id, bundle_id = register_user('test_user_3') account_1 = AccountPrototype.get_by_id(account_1_id) account_2 = AccountPrototype.get_by_id(account_2_id) storage = LogicStorage() storage.load_account_data(account_1) storage.load_account_data(account_2) hero_1 = storage.accounts_to_heroes[account_1.id] hero_2 = storage.accounts_to_heroes[account_2.id] hero_2._model.level = 50 self.assertEqual(hero_1.level, 1) MetaActionArenaPvP1x1Prototype.create(storage, hero_1, hero_2, bundle_id=self.bundle_id + 1) self.assertEqual(hero_1.level, 50) self.assertTrue(len(hero_1.abilities.all) > 1) self.assertEqual(hero_1.health, hero_1.max_health)
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 setUp(self): super(BaseRequestTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111') self.account_3 = AccountPrototype.get_by_id(account_id) group_edit_item = sync_group('edit item', ['collections.edit_item']) group_moderate_item = sync_group('moderate item', ['collections.moderate_item']) group_edit = sync_group('edit kit', ['collections.edit_kit']) group_moderate = sync_group('moderate kit', ['collections.moderate_kit']) group_edit_item.user_set.add(self.account_2._model) group_moderate_item.user_set.add(self.account_3._model) group_edit.user_set.add(self.account_2._model) group_moderate.user_set.add(self.account_3._model) self.collection_1 = CollectionPrototype.create(caption=u'collection_1', description=u'description_1') self.collection_2 = CollectionPrototype.create(caption=u'collection_2', description=u'description_2') self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1', approved=True) self.kit_2 = KitPrototype.create(collection=self.collection_1, caption=u'kit_2', description=u'description_2') self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'text_1_1') self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'text_1_2', approved=True)
def setUp(self): super(BuildingRepairTest, self).setUp() self.place_1, self.place_2, self.place_3 = 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') 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.ability_1 = self.PROCESSOR() self.ability_2 = self.PROCESSOR() environment.deinitialize() environment.initialize() self.highlevel = environment.workers.highlevel self.highlevel.process_initialize(0, 'highlevel') self.building = BuildingPrototype.create( self.place_1.persons[0], utg_name=names.generator.get_test_name('building-name')) self.building._model.integrity = 0.5 self.building.save()
def setUp(self): super(ArenaPvP1x1AcceptBaseTests, 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] environment.deinitialize() environment.initialize() self.pvp_balancer = environment.workers.pvp_balancer self.pvp_balancer.process_initialize('pvp_balancer') self.battle = self.pvp_balancer.add_to_arena_queue(self.hero_1.id)
def setUp(self): super(MetaProxyActionForArenaPvP1x1Tests, self).setUp() 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(AccountPrototype.get_by_id(self.account_1.id)) self.storage.load_account_data(AccountPrototype.get_by_id(self.account_2.id)) 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.action_idl_1 = self.hero_1.actions.current_action self.action_idl_2 = self.hero_2.actions.current_action 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) self.bundle_id = 666 meta_action_battle = meta_actions.ArenaPvP1x1.create(self.storage, self.hero_1, self.hero_2) self.action_proxy_1 = ActionMetaProxyPrototype.create(hero=self.hero_1, _bundle_id=self.bundle_id, meta_action=meta_action_battle) self.action_proxy_2 = ActionMetaProxyPrototype.create(hero=self.hero_2, _bundle_id=self.bundle_id, meta_action=meta_action_battle) self.storage.merge_bundles([self.action_idl_1.bundle_id, self.action_idl_2.bundle_id], self.bundle_id) self.meta_action_battle = self.storage.meta_actions.values()[0]
def test_process_bot__flame_ability_not_used(self): result, account_1_id, bundle_id = register_user("bot", "*****@*****.**", "111111", is_bot=True) result, account_2_id, bundle_id = register_user("test_user_3") account_1 = AccountPrototype.get_by_id(account_1_id) account_2 = AccountPrototype.get_by_id(account_2_id) storage = LogicStorage() storage.load_account_data(account_1) storage.load_account_data(account_2) hero_1 = storage.accounts_to_heroes[account_1.id] hero_2 = storage.accounts_to_heroes[account_2.id] MetaActionArenaPvP1x1Prototype.create(storage, hero_1, hero_2, bundle_id=self.bundle_id + 1) self.assertEqual(hero_2.pvp.energy_speed, 1) with mock.patch( "the_tale.game.actions.meta_actions.MetaActionArenaPvP1x1Prototype.get_bot_pvp_properties", lambda a: {"priorities": {Flame.TYPE: 1}, "ability_chance": 1}, ): with mock.patch("the_tale.game.pvp.abilities.Flame.use") as use: for i in xrange(100): self.meta_action_battle.process_bot(hero_1, hero_2) self.assertEqual(use.call_count, 0)
def test_initialize_bots__second_create(self): result, account_1_id, bundle_id = register_user("test_user_3") result, account_2_id, bundle_id = register_user("bot", "*****@*****.**", "111111", is_bot=True) account_1 = AccountPrototype.get_by_id(account_1_id) account_2 = AccountPrototype.get_by_id(account_2_id) storage = LogicStorage() storage.load_account_data(account_1) storage.load_account_data(account_2) hero_1 = storage.accounts_to_heroes[account_1.id] hero_2 = storage.accounts_to_heroes[account_2.id] hero_1._model.level = 50 self.assertEqual(hero_2.level, 1) self.pvp_create_battle(account_1, account_2, BATTLE_1X1_STATE.PROCESSING) self.pvp_create_battle(account_2, account_1, BATTLE_1X1_STATE.PROCESSING) meta_action = MetaActionArenaPvP1x1Prototype.create(storage, hero_1, hero_2, bundle_id=self.bundle_id + 1) meta_action.process_battle_ending() MetaActionArenaPvP1x1Prototype.create(storage, hero_1, hero_2, bundle_id=self.bundle_id + 2) self.assertEqual(hero_2.level, 50) self.assertTrue(len(hero_2.abilities.all) > 1) self.assertEqual(hero_2.health, hero_2.max_health)
def create_account(self, is_fast=False, password='******', is_bot=False, is_superuser=False): from the_tale.accounts.logic import register_user from the_tale.accounts.prototypes import AccountPrototype account_uid = self.get_next_uid() if is_fast: result, account_id, bundle_id = register_user('fast-user-%d' % account_uid, is_bot=is_bot) else: result, account_id, bundle_id = register_user( 'test-user-%d' % account_uid, '*****@*****.**' % account_uid, password, is_bot=is_bot) account = AccountPrototype.get_by_id(account_id) if is_superuser: account._model.is_superuser = True account.save() return AccountPrototype.get_by_id(account_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)
def test_process_add_to_arena_queue_two_requests_from_one_account(self): battle_1 = Battle1x1Prototype.create( AccountPrototype.get_by_id(self.account_1.id)) battle_2 = Battle1x1Prototype.create( AccountPrototype.get_by_id(self.account_1.id)) self.assertEqual(Battle1x1.objects.all().count(), 1) self.assertEqual(battle_1.id, battle_2.id)
def setUp(self): super(ArenaPvP1x1AbilityTest, 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") 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.ability_1 = self.PROCESSOR() self.ability_2 = self.PROCESSOR() environment.deinitialize() environment.initialize() self.pvp_balancer = environment.workers.pvp_balancer self.pvp_balancer.process_initialize("pvp_balancer")
def test_save_on_exception(self): # hero 1 not saved due to one bundle with hero 3 # hero 2 saved # hero 3 not saved # hero 4 saved result, account_3_id, bundle_3_id = register_user( 'test_user_3', '*****@*****.**', '111111') self.storage.load_account_data( AccountPrototype.get_by_id(account_3_id)) hero_3 = self.storage.accounts_to_heroes[account_3_id] result, account_4_id, bundle_4_id = register_user( 'test_user_4', '*****@*****.**', '111111') self.storage.load_account_data( AccountPrototype.get_by_id(account_4_id)) hero_4 = self.storage.accounts_to_heroes[account_4_id] self.hero_1.actions.current_action.bundle_id = hero_3.actions.current_action.bundle_id saved_heroes = set() def save_hero_data(storage, hero_id, **kwargs): saved_heroes.add(hero_id) self.storage.ignored_bundles.add( hero_3.actions.current_action.bundle_id) with mock.patch( 'the_tale.game.logic_storage.LogicStorage._save_hero_data', save_hero_data): self.storage._save_on_exception() self.assertEqual(saved_heroes, set([self.hero_2.id, hero_4.id]))
def setUp(self): super(_BaseRequestTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) group_edit = sync_group('edit achievement', ['achievements.edit_achievement']) group_edit.user_set.add(self.account_2._model) self.achievement_1 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=0, points=10, caption=u'achievement_1', description=u'description_1', approved=True) self.achievement_2 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=2, points=10, caption=u'achievement_2', description=u'description_2', approved=False) self.achievement_3 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.TIME, type=ACHIEVEMENT_TYPE.TIME, barrier=3, points=10, caption=u'achievement_3', description=u'description_3', approved=True) self.collection_1 = CollectionPrototype.create(caption=u'collection_1', description=u'description_1', approved=True) self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1', approved=True) self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'text_1_1', approved=True) self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'text_1_2', approved=True) self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(self.account_1.id) self.account_achievements_1.achievements.add_achievement(self.achievement_1) self.account_achievements_1.save()
def setUp(self): super(MetaProxyActionForArenaPvP1x1Tests, self).setUp() create_test_map() result, account_1_id, bundle_id = register_user('test_user_1', '*****@*****.**', '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(AccountPrototype.get_by_id(self.account_1.id)) self.storage.load_account_data(AccountPrototype.get_by_id(self.account_2.id)) self.hero_1 = self.storage.accounts_to_heroes[account_1_id] self.hero_2 = self.storage.accounts_to_heroes[account_2_id] self.action_idl_1 = self.hero_1.actions.current_action self.action_idl_2 = self.hero_2.actions.current_action 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) self.bundle_id = 666 meta_action_battle = MetaActionArenaPvP1x1Prototype.create(self.storage, self.hero_1, self.hero_2, bundle_id=self.bundle_id) self.action_proxy_1 = ActionMetaProxyPrototype.create(hero=self.hero_1, _bundle_id=self.bundle_id, meta_action=meta_action_battle) self.action_proxy_2 = ActionMetaProxyPrototype.create(hero=self.hero_2, _bundle_id=self.bundle_id, meta_action=meta_action_battle) self.storage.merge_bundles([self.action_idl_1.bundle_id, self.action_idl_2.bundle_id], self.bundle_id) self.meta_action_battle = self.storage.meta_actions.values()[0]
def _initiate_battle(self, record_1, record_2, calculate_ratings=False): from the_tale.accounts.prototypes import AccountPrototype account_1 = AccountPrototype.get_by_id(record_1.account_id) account_2 = AccountPrototype.get_by_id(record_2.account_id) self.logger.info("start battle between accounts %d and %d" % (account_1.id, account_2.id)) with transaction.atomic(): battle_1 = Battle1x1Prototype.get_by_id(record_1.battle_id) battle_2 = Battle1x1Prototype.get_by_id(record_2.battle_id) battle_1.set_enemy(account_2) battle_2.set_enemy(account_1) if ( calculate_ratings and abs(record_1.hero_level - record_2.hero_level) <= pvp_settings.BALANCING_MIN_LEVEL_DELTA ): battle_1.calculate_rating = True battle_2.calculate_rating = True battle_1.save() battle_2.save() task = SupervisorTaskPrototype.create_arena_pvp_1x1(account_1, account_2) environment.workers.supervisor.cmd_add_task(task.id)
def setUp(self): super(RepairBuildingTests, self).setUp() self.place_1, self.place_2, self.place_3 = 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') 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 = self.storage.accounts_to_heroes[self.account_1.id] self.card = self.CARD() environment.deinitialize() environment.initialize() self.highlevel = environment.workers.highlevel self.highlevel.process_initialize(0, 'highlevel') self.building_1 = BuildingPrototype.create( person=self.place_1.persons[0], utg_name=names.generator.get_test_name('building-1-name')) self.building_2 = BuildingPrototype.create( person=self.place_2.persons[0], utg_name=names.generator.get_test_name('building-1-name')) self.building_1.amortize(c.TURNS_IN_HOUR * 24) self.building_2.amortize(c.TURNS_IN_HOUR * 24)
def setUp(self): super(LogicStorageTests, self).setUp() self.p1, self.p2, self.p3 = create_test_map() self.storage = LogicStorage() result, account_1_id, bundle_1_id = register_user( 'test_user_1', '*****@*****.**', '111111') result, account_2_id, bundle_2_id = register_user( 'test_user_2', '*****@*****.**', '111111') self.bundle_1_id = bundle_1_id self.bundle_2_id = bundle_2_id self.account_1 = AccountPrototype.get_by_id(account_1_id) self.account_2 = AccountPrototype.get_by_id(account_2_id) self.storage.load_account_data( AccountPrototype.get_by_id(account_1_id)) self.storage.load_account_data( AccountPrototype.get_by_id(account_2_id)) self.hero_1 = self.storage.accounts_to_heroes[account_1_id] self.hero_2 = self.storage.accounts_to_heroes[account_2_id] self.action_idl_1 = self.hero_1.actions.current_action self.action_idl_2 = self.hero_2.actions.current_action
def process(self): from the_tale.accounts.personal_messages import tt_api as pm_tt_api message = pm_tt_api.get_message(self.account_id, message_id=self.message_id) if message is None: return True # message can be removed by admins or with removed thread account = AccountPrototype.get_by_id(self.account_id) if not account.personal_messages_subscription: return True if account.id == get_system_user().id or account.is_bot: return True if not account.email: return True subject = '«Сказка»: личное сообщение' context = {'message': message, 'sender': AccountPrototype.get_by_id(message.sender_id)} html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context) text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context) return logic.send_mail([account], subject, text_content, html_content)
def setUp(self): super(AchievementsManagerTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) group_edit = sync_group('edit achievement', ['achievements.edit_achievement']) group_edit.user_set.add(self.account_2._model) self.achievement_1 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=0, points=10, caption=u'achievement_1', description=u'description_1', approved=True) self.achievement_2 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=5, points=10, caption=u'achievement_2', description=u'description_2', approved=False) self.achievement_3 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.TIME, type=ACHIEVEMENT_TYPE.DEATHS, barrier=4, points=10, caption=u'achievement_3', description=u'description_3', approved=True) self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(self.account_1.id) self.account_achievements_1.achievements.add_achievement(self.achievement_1) self.account_achievements_1.save() self.worker = environment.workers.achievements_manager self.worker.initialize()
def _initiate_battle(self, record_1, record_2, calculate_ratings=False): from the_tale.accounts.prototypes import AccountPrototype account_1 = AccountPrototype.get_by_id(record_1.account_id) account_2 = AccountPrototype.get_by_id(record_2.account_id) self.logger.info('start battle between accounts %d and %d' % (account_1.id, account_2.id)) with transaction.atomic(): battle_1 = Battle1x1Prototype.get_by_id(record_1.battle_id) battle_2 = Battle1x1Prototype.get_by_id(record_2.battle_id) battle_1.set_enemy(account_2) battle_2.set_enemy(account_1) if calculate_ratings and abs( record_1.hero_level - record_2.hero_level ) <= pvp_settings.BALANCING_MIN_LEVEL_DELTA: battle_1.calculate_rating = True battle_2.calculate_rating = True battle_1.save() battle_2.save() task = SupervisorTaskPrototype.create_arena_pvp_1x1( account_1, account_2) environment.workers.supervisor.cmd_add_task(task.id)
def process_battle_ending(self): battle_1 = Battle1x1Prototype.get_by_account_id(self.hero_1.account_id) battle_2 = Battle1x1Prototype.get_by_account_id(self.hero_2.account_id) participant_1 = AccountPrototype.get_by_id(self.hero_1.account_id) participant_2 = AccountPrototype.get_by_id(self.hero_2.account_id) if self.hero_1.health <= 0: if self.hero_2.health <= 0: Battle1x1ResultPrototype.create(participant_1=participant_1, participant_2=participant_2, result =BATTLE_1X1_RESULT.DRAW) if battle_1.calculate_rating and battle_2.calculate_rating: self.hero_1.statistics.change_pvp_battles_1x1_draws(1) self.hero_2.statistics.change_pvp_battles_1x1_draws(1) else: Battle1x1ResultPrototype.create(participant_1=participant_1, participant_2=participant_2, result =BATTLE_1X1_RESULT.DEFEAT) if battle_1.calculate_rating and battle_2.calculate_rating: self.hero_2.statistics.change_pvp_battles_1x1_victories(1) self.hero_1.statistics.change_pvp_battles_1x1_defeats(1) else: Battle1x1ResultPrototype.create(participant_1=participant_1, participant_2=participant_2, result =BATTLE_1X1_RESULT.VICTORY) if battle_1.calculate_rating and battle_2.calculate_rating: self.hero_1.statistics.change_pvp_battles_1x1_victories(1) self.hero_2.statistics.change_pvp_battles_1x1_defeats(1) battle_1.remove() battle_2.remove() self.hero_1.health = self.hero_1_old_health self.hero_2.health = self.hero_2_old_health self.state = self.STATE.PROCESSED
def setUp(self): super(ArenaPvP1x1AbilityTest, 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') 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.ability_1 = self.PROCESSOR() self.ability_2 = self.PROCESSOR() environment.deinitialize() environment.initialize() self.pvp_balancer = environment.workers.pvp_balancer self.pvp_balancer.process_initialize('pvp_balancer')
def test_save_on_exception__time_border(self): # hero 1 not saved due to one bundle with hero 3 # hero 2 saved # hero 3 not saved # hero 4 saved result, account_3_id, bundle_3_id = register_user('test_user_3', '*****@*****.**', '111111') self.storage.load_account_data(AccountPrototype.get_by_id(account_3_id)) hero_3 = self.storage.accounts_to_heroes[account_3_id] result, account_4_id, bundle_4_id = register_user('test_user_4', '*****@*****.**', '111111') self.storage.load_account_data(AccountPrototype.get_by_id(account_4_id)) hero_4 = self.storage.accounts_to_heroes[account_4_id] self.hero_1.actions.current_action.bundle_id = hero_3.actions.current_action.bundle_id saved_heroes = set() self.hero_2._model.saved_at = datetime.datetime.now() - datetime.timedelta(seconds=conf.game_settings.SAVE_ON_EXCEPTION_TIMEOUT+1) def save_hero_data(storage, hero_id, **kwargs): saved_heroes.add(hero_id) self.storage.ignored_bundles.add(hero_3.actions.current_action.bundle_id) with mock.patch('the_tale.game.logic_storage.LogicStorage._save_hero_data', save_hero_data): self.storage._save_on_exception() self.assertEqual(saved_heroes, set([self.hero_2.id]))
def test_get_bundles_to_save__without_cache_dump(self): # hero 1 not saved # hero 2 saved by quota # hero 3 does not saved by caching # hero 4 not saved result, account_3_id, bundle_3_id = register_user('test_user_3', '*****@*****.**', '111111') result, account_4_id, bundle_4_id = register_user('test_user_4', '*****@*****.**', '111111') self.storage.load_account_data(AccountPrototype.get_by_id(account_3_id)) self.storage.load_account_data(AccountPrototype.get_by_id(account_4_id)) hero_3 = self.storage.accounts_to_heroes[account_3_id] hero_4 = self.storage.accounts_to_heroes[account_4_id] self.hero_1._model.saved_at = datetime.datetime.now() self.hero_1.ui_caching_started_at = datetime.datetime.fromtimestamp(0) self.hero_2.ui_caching_started_at = datetime.datetime.fromtimestamp(0) hero_4.ui_caching_started_at = datetime.datetime.fromtimestamp(0) self.assertTrue(self.hero_1.saved_at > self.hero_2.saved_at) self.assertFalse(self.hero_1.is_ui_caching_required) self.assertFalse(self.hero_2.is_ui_caching_required) self.assertTrue(hero_3.is_ui_caching_required) self.assertFalse(hero_4.is_ui_caching_required) self.assertEqual(self.storage._get_bundles_to_save(), set([self.bundle_2_id]))
def test_save_on_exception(self): # hero 1 not saved due to one bundle with hero 3 # hero 2 saved # hero 3 not saved # hero 4 saved result, account_3_id, bundle_3_id = register_user('test_user_3', '*****@*****.**', '111111') self.storage.load_account_data(AccountPrototype.get_by_id(account_3_id)) hero_3 = self.storage.accounts_to_heroes[account_3_id] result, account_4_id, bundle_4_id = register_user('test_user_4', '*****@*****.**', '111111') self.storage.load_account_data(AccountPrototype.get_by_id(account_4_id)) hero_4 = self.storage.accounts_to_heroes[account_4_id] self.hero_1.actions.current_action.bundle_id = hero_3.actions.current_action.bundle_id saved_heroes = set() def save_hero_data(storage, hero_id, **kwargs): saved_heroes.add(hero_id) self.storage.ignored_bundles.add(hero_3.actions.current_action.bundle_id) with mock.patch('the_tale.game.logic_storage.LogicStorage._save_hero_data', save_hero_data): self.storage._save_on_exception() self.assertEqual(saved_heroes, set([self.hero_2.id, hero_4.id]))
def test_change_credentials__with_referral(self): self.fast_account._model.referral_of = self.account._model self.fast_account.save() self.assertTrue( AccountPrototype.get_by_id(self.fast_account.id).is_fast) with mock.patch( 'the_tale.game.workers.supervisor.Worker.cmd_update_hero_with_account_data' ) as fake_cmd: with mock.patch( 'the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method' ) as cmd_run_account_method: self.fast_account.change_credentials( new_email='*****@*****.**', new_password=make_password('222222'), new_nick='test_nick') self.assertEqual(cmd_run_account_method.call_count, 1) self.assertEqual( cmd_run_account_method.call_args, mock.call( account_id=self.account.id, method_name=AccountPrototype.update_referrals_number.__name__, data={})) self.assertEqual( django_authenticate(nick='test_nick', password='******').id, self.fast_account.id) self.assertFalse( AccountPrototype.get_by_id(self.fast_account.id).is_fast) self.assertEqual(fake_cmd.call_count, 1) self.assertFalse(fake_cmd.call_args[1]['is_fast'])
def create_account(self, is_fast=False, nick=None, email=None, password='******', is_bot=False, is_superuser=False, referral_of_id=None): from the_tale.accounts.logic import register_user from the_tale.accounts.prototypes import AccountPrototype if is_fast: nick = nick or 'fast-user-{}'.format(self.get_next_uid()) result, account_id, bundle_id = register_user( nick, is_bot=is_bot, referral_of_id=referral_of_id) else: nick = nick or 'test-user-%d' % self.get_next_uid() email = email or '{}@test.com'.format(nick) result, account_id, bundle_id = register_user( nick, email, password, is_bot=is_bot, referral_of_id=referral_of_id) account = AccountPrototype.get_by_id(account_id) if is_superuser: account._model.is_superuser = True account.save() return AccountPrototype.get_by_id(account_id)
def setUp(self): super(BuildingRepairTest, self).setUp() self.place_1, self.place_2, self.place_3 = 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') 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.ability_1 = self.PROCESSOR() self.ability_2 = self.PROCESSOR() environment.deinitialize() environment.initialize() self.highlevel = environment.workers.highlevel self.highlevel.process_initialize(0, 'highlevel') self.building = BuildingPrototype.create(self.place_1.persons[0], utg_name=names.generator.get_test_name('building-name')) self.building._model.integrity = 0.5 self.building.save()
def handle(self, *args, **options): # pylint: disable=R0914 # account = AccountPrototype.get_by_nick('compare_abilities_user') # if account: # account.remove() # account = AccountPrototype.get_by_nick('compare_abilities_user_2') # if account: # account.remove() result, account_1_id, bundle_id = register_user('compare_abilities_user') # pylint: disable=W0612 result, account_2_id, bundle_id = register_user('compare_abilities_user_2') # pylint: disable=W0612 account_1 = AccountPrototype.get_by_id(account_1_id) account_2 = AccountPrototype.get_by_id(account_2_id) storage = LogicStorage() storage.load_account_data(account_1) storage.load_account_data(account_2) hero_1 = storage.accounts_to_heroes[account_1_id] hero_2 = storage.accounts_to_heroes[account_2_id] set_heroes_companion(hero_1, hero_2) try: abilities = [ability_class for ability_class in ABILITIES.values() if (ability_class.AVAILABILITY.value & ABILITY_AVAILABILITY.FOR_PLAYERS.value and ability_class.get_id() != 'hit' and ability_class.TYPE == ABILITY_TYPE.BATTLE) ] ability_matches = compare_abilities(hero_1, hero_2, abilities, level=LEVEL) ability_statistics = dict( (ability.get_id(), 0) for ability in abilities) ability_wins = dict( (ability.get_id(), []) for ability in abilities) for (ability_1_id, ability_2_id), (ability_1_wins, ability_2_wins) in ability_matches.items(): ability_statistics[ability_1_id] = ability_statistics.get(ability_1_id, 0) + ability_1_wins ability_statistics[ability_2_id] = ability_statistics.get(ability_2_id, 0) + ability_2_wins ability_wins[ability_1_id].append(ability_1_wins) ability_wins[ability_2_id].append(ability_2_wins) statistics = sorted(ability_statistics.items(), key=lambda stat: -stat[1]) battles_per_ability = TEST_BATTLES_NUMBER * (len(abilities)-1) for ability_id, wins in statistics: print '%d\t%.0f%%\t%s' % (wins, 100*float(wins)/(battles_per_ability*len(HERO_LEVELS)), ability_id) save_ability_power_statistics(statistics) save_ability_mathces_statistics(statistics, ability_matches) save_ability_wins_distribution(statistics, ability_wins) finally: remove_account(account_1) remove_account(account_2)
def setUp(self): super(TestChangeCredentialsTask, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.test_account = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('fast_user') self.fast_account = AccountPrototype.get_by_id(account_id)
def setUp(self): super(AccountPrototypeTests, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() result, account_id, bundle_id = register_user("test_user", "*****@*****.**", "111111") self.account = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user("fast_user") self.fast_account = AccountPrototype.get_by_id(account_id)
def setUp(self): super(FormGameInfoTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user_1') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2') self.account_2 = AccountPrototype.get_by_id(account_id)
def setUp(self): super(SupervisorTaskTests, 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)
def setUp(self): super(AccountPrototypeTests, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.account = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('fast_user') self.fast_account = AccountPrototype.get_by_id(account_id)
def setUp(self): super(BaseRequestTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111') self.account_3 = AccountPrototype.get_by_id(account_id) group_edit_item = sync_group('edit item', ['collections.edit_item']) group_moderate_item = sync_group('moderate item', ['collections.moderate_item']) group_edit = sync_group('edit kit', ['collections.edit_kit']) group_moderate = sync_group('moderate kit', ['collections.moderate_kit']) group_edit_item.user_set.add(self.account_2._model) group_moderate_item.user_set.add(self.account_3._model) group_edit.user_set.add(self.account_2._model) group_moderate.user_set.add(self.account_3._model) self.collection_1 = CollectionPrototype.create( caption=u'collection_1', description=u'description_1') self.collection_2 = CollectionPrototype.create( caption=u'collection_2', description=u'description_2') self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1', approved=True) self.kit_2 = KitPrototype.create(collection=self.collection_1, caption=u'kit_2', description=u'description_2') self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'text_1_1') self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'text_1_2', approved=True)
def setUp(self): super(SupervisorTaskTests, 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)
def setUp(self): super(FriendshipPrototypeTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111') self.account_3 = AccountPrototype.get_by_id(account_id)
def setUp(self): super(MembershipPrototypeTests, self).setUp() self.forum_category = CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) create_test_map() result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.account = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) self.clan = self.create_clan(self.account, 0)
def test_change_credentials(self): self.assertTrue(AccountPrototype.get_by_id(self.fast_account.id).is_fast) with mock.patch('the_tale.game.workers.supervisor.Worker.cmd_update_hero_with_account_data') as fake_cmd: with mock.patch('the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method') as cmd_run_account_method: self.fast_account.change_credentials(new_email='*****@*****.**', new_password=make_password('222222'), new_nick='test_nick') self.assertEqual(cmd_run_account_method.call_count, 0) self.assertEqual(django_authenticate(nick='test_nick', password='******').id, self.fast_account.id) self.assertFalse(AccountPrototype.get_by_id(self.fast_account.id).is_fast) self.assertEqual(fake_cmd.call_count, 1) self.assertFalse(fake_cmd.call_args[1]['is_fast'])
def setUp(self): super(CalculateMightTests, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.account = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111', referral_of_id=self.account.id) self.account_2 = AccountPrototype.get_by_id(account_id) self.forum_category = CategoryPrototype.create('category', 'category-slug', 0) self.bills_subcategory = SubCategoryPrototype.create(self.forum_category, 'subcategory', order=0, uid=bills_settings.FORUM_CATEGORY_UID) self.blogs_subcategory = SubCategoryPrototype.create(self.forum_category, blogs_conf.settings.FORUM_CATEGORY_UID + '-caption', order=1, uid=blogs_conf.settings.FORUM_CATEGORY_UID)
def setUp(self): super(RandomPremiumRequestPrototypeTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) AccountPrototype._db_all().update(created_at=datetime.datetime.now() - accounts_settings.RANDOM_PREMIUM_CREATED_AT_BARRIER) self.request = RandomPremiumRequestPrototype.create(self.account_1.id, days=30)
def setUp(self): super(BaseRequestsTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('moderator', '*****@*****.**', '111111') self.moderator = AccountPrototype.get_by_id(account_id) group = sync_group(linguistics_settings.MODERATOR_GROUP_NAME, ['linguistics.moderate_word']) group.user_set.add(self.moderator._model)
def test_successfull_result(self): 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 = HeroPrototype.get_by_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(HeroPreferencesPrototype._db_count(), 1) self.assertEqual( HeroPreferencesPrototype.get_by_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(market_models.Goods.objects.count(), 1)
def test_successfull_result__is_bot(self): result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111', is_bot=True) account = AccountPrototype.get_by_id(account_id) self.assertEqual(account.is_bot, True)