def check_heroes(self): result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') hero_1 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') hero_2 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111') hero_3 = HeroPrototype.get_by_account_id(account_id) hero_1.premium_state_end_at = datetime.datetime.now() + datetime.timedelta(seconds=60) hero_1.preferences.set_place(self.place_1) hero_1.preferences.set_friend(self.place_1.persons[0]) hero_1.preferences.set_enemy(self.place_1.persons[-1]) hero_1.save() hero_2.premium_state_end_at = datetime.datetime.now() + datetime.timedelta(seconds=60) hero_2.preferences.set_place(self.place_1) hero_2.preferences.set_friend(self.place_1.persons[-1]) hero_2.preferences.set_enemy(self.place_1.persons[0]) hero_2.save() hero_3.preferences.set_place(self.place_1) hero_3.preferences.set_friend(self.place_1.persons[-1]) hero_3.preferences.set_enemy(self.place_1.persons[0]) hero_3.save() texts = [(jinja2.escape(hero_1.name), 3), (jinja2.escape(hero_2.name), 3), (jinja2.escape(hero_3.name), 0)] self.check_html_ok(self.request_html(url('game:map:places:show', self.place_1.id)), texts=texts)
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 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(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_successfull_result__referral(self): _, owner_id, _ = register_user('test_user', '*****@*****.**', '111111') _, account_id, _ = register_user('test_user_2', '*****@*****.**', '111111', referral_of_id=owner_id) account = AccountPrototype.get_by_id(account_id) self.assertEqual(account.referral_of_id, owner_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(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 __init__(self): register_user('forum_user', '*****@*****.**', '111111') register_user('forum_user_2', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_nick('forum_user') self.account_2 = AccountPrototype.get_by_nick('forum_user_2') # cat1 # |-subcat1 # | |-thread1 # | | |-post1 # | |-thread2 # |-subcat2 # cat2 # | subcat3 # | |- thread3 # cat3 self.cat_1 = CategoryPrototype.create(caption='cat1-caption', slug='cat1-slug', order=0) # to test, that subcat.id not correlate with order self.subcat_2 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat2-caption', order=1, closed=True) self.subcat_1 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat1-caption', order=0) self.cat_2 = CategoryPrototype.create(caption='cat2-caption', slug='cat2-slug', order=0) self.subcat_3 = SubCategoryPrototype.create(category=self.cat_2, caption='subcat3-caption', order=0) self.cat_3 = CategoryPrototype.create(caption='cat3-caption', slug='cat3-slug', order=0) self.thread_1 = ThreadPrototype.create(self.subcat_1, 'thread1-caption', self.account_1, 'thread1-text') self.thread_2 = ThreadPrototype.create(self.subcat_1, 'thread2-caption', self.account_1, 'thread2-text') self.thread_3 = ThreadPrototype.create(self.subcat_3, 'thread3-caption', self.account_1, 'thread3-text') self.post_1 = PostPrototype.create(self.thread_1, self.account_1, 'post1-text') # create test clan and clean it's forum artifacts self.clan_category = CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_1 = ClanPrototype.create(self.account_1, abbr=u'abbr1', name=u'name1', motto=u'motto', description=u'description')
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_fast_accounts_filtration(self): register_user("user_5") RatingValuesPrototype.recalculate() self.assertEqual( [rv.account_id for rv in RatingValues.objects.all().order_by("account__id")], [self.account_1.id, self.account_2.id, self.account_3.id, self.account_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) 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 test_last_forum_posts_with_permissions(self): register_user('granted_user', '*****@*****.**', '111111') register_user('wrong_user', '*****@*****.**', '111111') granted_account = AccountPrototype.get_by_nick('granted_user') wrong_account = AccountPrototype.get_by_nick('wrong_user') restricted_subcategory = SubCategoryPrototype.create( category=self.category, caption='subcat2-caption', order=1, restricted=True) PermissionPrototype.create(granted_account, restricted_subcategory) restricted_thread = ThreadPrototype.create( restricted_subcategory, 'thread-restricted-caption', self.account, 'thread-text') self.assertEqual( set(t.id for t in ThreadPrototype.get_last_threads(account=None, limit=3)), set([self.thread.id])) self.assertEqual( set(t.id for t in ThreadPrototype.get_last_threads( account=granted_account, limit=3)), set([self.thread.id, restricted_thread.id])) self.assertEqual( set(t.id for t in ThreadPrototype.get_last_threads( account=wrong_account, limit=3)), set([self.thread.id]))
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 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 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_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_duplicate_email(self): result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.assertEqual(result, REGISTER_USER_RESULT.OK) self.assertTrue(bundle_id is not None) result, account_id, bundle_id = register_user('test_user2', '*****@*****.**', '111111') self.assertEqual(result, REGISTER_USER_RESULT.DUPLICATE_EMAIL) self.assertTrue(bundle_id is None)
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_successfull_result__wrong_referral(self): result, owner_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111', referral_of_id='%dxxx' % owner_id) account = AccountPrototype.get_by_id(account_id) self.assertEqual(account.referral_of_id, None)
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(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 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 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 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 test_process_duplicated_email(self): register_user('duplicated_user', '*****@*****.**', '111111') task = ChangeCredentialsTaskPrototype.create( self.test_account, new_email='*****@*****.**') task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.EMAIL_SENT task.process(FakeLogger()) self.assertEqual(task._model.state, relations.CHANGE_CREDENTIALS_TASK_STATE.ERROR)
def test_successfull_result__referral(self): result, owner_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111', referral_of_id=owner_id) account = AccountPrototype.get_by_id(account_id) self.assertEqual(account.referral_of_id, owner_id)
def test_successfull_result__action(self): result, owner_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111', action_id='action') account = AccountPrototype.get_by_id(account_id) self.assertEqual(account.action_id, 'action')
def test_profile_update_duplicate_nick(self): register_user('duplicated_user', '*****@*****.**', '111111') self.request_login(self.account.email) response = self.client.post(reverse('accounts:profile:update'), {'nick': 'duplicated_user', 'email': '*****@*****.**'}) self.check_ajax_error(response, 'accounts.profile.update.used_nick') self.assertEqual(ChangeCredentialsTask.objects.all().count(), 0) self.assertEqual(Message.objects.all().count(), 0) self.assertEqual(django_authenticate(nick=self.account_nick, password='******').id, self.account.id) self.assertEqual(django_authenticate(nick=self.account_nick, password='******').email, self.account_email)
def test_update_referrals(self): register_user('user_2', '*****@*****.**', '111111', referral_of_id=self.account.id) register_user('fast_user_3', referral_of_id=self.account.id) self.account.update_referrals_number() self.fast_account.update_referrals_number() self.assertEqual(self.account.referrals_number, 1) self.assertEqual(self.fast_account.referrals_number, 0)
def setUp(self): super(ResetPasswordTests, self).setUp() create_test_map() register_user('user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_nick('user_1') self.reset_task = ResetPasswordTaskPrototype.create(self.account_1) self.message = MessagePrototype.get_priority_message()
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(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 test_update_referrals(self): register_user("user_2", "*****@*****.**", "111111", referral_of_id=self.account.id) register_user("fast_user_3", referral_of_id=self.account.id) self.account.update_referrals_number() self.fast_account.update_referrals_number() self.assertEqual(self.account.referrals_number, 1) self.assertEqual(self.fast_account.referrals_number, 0)
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(SendMailTests, self).setUp() create_test_map() register_user('user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_nick('user_1') register_user('user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_nick('user_2')
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(TestRequestsBase, self).setUp() create_test_map() self.client = client.Client() register_user('test_user', '*****@*****.**', '111111') register_user('test_user_2', '*****@*****.**', '111111') account = django_authenticate(nick='test_user_2', password='******') account.is_staff = True account.save()
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 test_successfull_result__wrong_referral(self): _, owner_id, _ = register_user('test_user', '*****@*****.**', '111111') _, account_id, _ = register_user('test_user_2', '*****@*****.**', '111111', referral_of_id='%dxxx' % owner_id) account = AccountPrototype.get_by_id(account_id) self.assertEqual(account.referral_of_id, None)
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 setUp(self): super(NewForumThreadTests, self).setUp() create_test_map() register_user('user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_nick('user_1') self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0) self.subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat-caption', order=0) self.thread = ThreadPrototype.create(self.subcategory, 'thread_1-caption', self.account_1, 'thread-text') self.message = MessagePrototype.get_priority_message()
def test_fast_accounts_filtration(self): register_user('user_5') RatingValuesPrototype.recalculate() self.assertEqual([ rv.account_id for rv in RatingValues.objects.all().order_by('account__id') ], [ self.account_1.id, self.account_2.id, self.account_3.id, self.account_4.id, ])
def setUp(self): super(AbilitiesTests, self).setUp() create_test_map() result, account_1_id, bundle_id = register_user( 'test_user_1', '*****@*****.**', '111111') result, account_1_id, bundle_id = register_user( 'test_user_2', '*****@*****.**', '111111') self.hero = heroes_logic.load_hero(account_id=account_1_id) self.enemy = heroes_logic.load_hero(account_id=account_1_id)
def setUp(self): super(AbilitiesTests, self).setUp() create_test_map() result, account_1_id, bundle_id = register_user( 'test_user_1', '*****@*****.**', '111111') result, account_1_id, bundle_id = register_user( 'test_user_2', '*****@*****.**', '111111') self.hero = HeroPrototype.get_by_account_id(account_1_id) self.enemy = HeroPrototype.get_by_account_id(account_1_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(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(PermissionPrototypeTests, self).setUp() create_test_map() register_user('user_1', '*****@*****.**', '111111') self.account = AccountPrototype.get_by_nick('user_1') self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0) self.subcategory = SubCategoryPrototype.create( category=self.category, caption='subcat-caption', order=0)
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 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(ChooseRequestsTests, self).setUp() create_test_map() register_user('test_user', '*****@*****.**', '111111') account = AccountPrototype.get_by_email('*****@*****.**') self.storage = LogicStorage() self.storage.load_account_data(AccountPrototype.get_by_id(account.id)) self.hero = self.storage.accounts_to_heroes[account.id] self.choice_uid = '[ns-0]choice_1' self.option_uid = '#option<[ns-0]choice_1, [ns-0]choice_2>'
def test_many_subscriptions(self): register_user('user_2', '*****@*****.**', '111111') account_2 = AccountPrototype.get_by_nick('user_2') SubscriptionPrototype.create(self.account_1, self.thread) SubscriptionPrototype.create(account_2, self.thread) self.assertEqual(len(mail.outbox), 0) self.message.process() self.assertTrue(self.message.state.is_PROCESSED) self.assertEqual(len(mail.outbox), 2) self.assertEqual(mail.outbox[0].to, [self.account_1.email]) self.assertEqual(mail.outbox[1].to, [account_2.email])
def setUp(self): super(PersonalMessagesTests, self).setUp() create_test_map() register_user('user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_nick('user_1') register_user('user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_nick('user_2') self.personal_message = PersonalMessagePrototype.create( self.account_1, self.account_2, 'test text') self.message = MessagePrototype.get_priority_message()
def setUp(self): super(HabilitiesViewsTest, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.storage = LogicStorage() self.storage.load_account_data(AccountPrototype.get_by_id(account_id)) self.hero = self.storage.accounts_to_heroes[account_id] register_user('test_user_2', '*****@*****.**', '111111') self.client = client.Client()
def create_account(self, is_fast=False, password='******'): 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) else: result, account_id, bundle_id = register_user( 'test-user-%d' % account_uid, '*****@*****.**' % account_uid, password) return AccountPrototype.get_by_id(account_id)