def test_legendary_achievements(self): achievement_4 = AchievementPrototype.create( group=ACHIEVEMENT_GROUP.LEGENDS, type=ACHIEVEMENT_TYPE.LEGENDS, barrier=0, points=0, caption=u'achievement_4', description=u'description_4', approved=True) self.account_achievements_1.achievements.add_achievement(achievement_4) self.account_achievements_1.save() GiveAchievementTaskPrototype.create(account_id=None, achievement_id=achievement_4.id) account_achievements_2 = AccountAchievementsPrototype.get_by_account_id( self.account_2.id) self.assertTrue( self.account_achievements_1.has_achievement(achievement_4)) self.assertFalse(account_achievements_2.has_achievement(achievement_4)) with self.check_not_changed(MessagePrototype._db_count): self.worker.add_achievements() self.account_achievements_1.reload() account_achievements_2.reload() self.assertTrue( self.account_achievements_1.has_achievement(achievement_4)) self.assertFalse(account_achievements_2.has_achievement(achievement_4)) self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
def test_add_achievements__all_accounts(self): GiveAchievementTaskPrototype.create( account_id=None, achievement_id=self.achievement_3.id) account_achievements_2 = AccountAchievementsPrototype.get_by_account_id( self.account_2.id) self.assertFalse( self.account_achievements_1.has_achievement(self.achievement_3)) self.assertFalse( account_achievements_2.has_achievement(self.achievement_3)) hero = heroes_logic.load_hero(account_id=self.account_1.id) hero.statistics.change_pve_deaths(self.achievement_3.barrier) heroes_logic.save_hero(hero) with self.check_not_changed(MessagePrototype._db_count): self.worker.add_achievements() self.account_achievements_1.reload() account_achievements_2.reload() self.assertTrue( self.account_achievements_1.has_achievement(self.achievement_3)) self.assertFalse( account_achievements_2.has_achievement(self.achievement_3)) self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
def test_add_achievements__all_accounts__not_remove_already_received_achievements( self): self.account_achievements_1.achievements.add_achievement( self.achievement_3) self.account_achievements_1.save() GiveAchievementTaskPrototype.create( account_id=None, achievement_id=self.achievement_3.id) account_achievements_2 = AccountAchievementsPrototype.get_by_account_id( self.account_2.id) self.assertTrue( self.account_achievements_1.has_achievement(self.achievement_3)) self.assertFalse( account_achievements_2.has_achievement(self.achievement_3)) with self.check_not_changed(MessagePrototype._db_count): self.worker.add_achievements() self.account_achievements_1.reload() account_achievements_2.reload() self.assertTrue( self.account_achievements_1.has_achievement(self.achievement_3)) self.assertFalse( account_achievements_2.has_achievement(self.achievement_3)) self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
def test_add_achievements(self): GiveAchievementTaskPrototype.create(account_id=self.account_1.id, achievement_id=self.achievement_3.id) self.assertFalse(self.account_achievements_1.has_achievement(self.achievement_3)) with self.check_delta(MessagePrototype._db_count, 1): self.worker.add_achievements() self.account_achievements_1.reload() self.assertTrue(self.account_achievements_1.has_achievement(self.achievement_3)) self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
def test_add_achievements(self): GiveAchievementTaskPrototype.create( account_id=self.account_1.id, achievement_id=self.achievement_3.id) self.assertFalse( self.account_achievements_1.has_achievement(self.achievement_3)) with self.check_new_message(self.account_1.id, [accounts_logic.get_system_user_id()]): self.worker.add_achievements() self.account_achievements_1.reload() self.assertTrue( self.account_achievements_1.has_achievement(self.achievement_3)) self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
def update(self): form = EditAchievementForm(self.request.POST) if not form.is_valid(): return self.json_error('accounts.achievements.update.form_errors', form.errors) with transaction.atomic(): is_changed = (self.achievement.type != form.c.type or self.achievement.approved != form.c.approved or self.achievement.barrier != form.c.barrier or self.achievement.points != form.c.points or self.achievement.item_1 != form.c.item_1 or self.achievement.item_2 != form.c.item_2 or self.achievement.item_3 != form.c.item_3) self.achievement.group = form.c.group self.achievement.type = form.c.type self.achievement.caption = form.c.caption self.achievement.description = form.c.description self.achievement.approved = form.c.approved self.achievement.barrier = form.c.barrier self.achievement.points = form.c.points self.achievement.order = form.c.order self.achievement.item_1_id = form.c.item_1.id if form.c.item_1 is not None else None self.achievement.item_2_id = form.c.item_2.id if form.c.item_2 is not None else None self.achievement.item_3_id = form.c.item_3.id if form.c.item_3 is not None else None self.achievement.save() if is_changed: GiveAchievementTaskPrototype.create( account_id=None, achievement_id=self.achievement.id) return self.json_ok( data={ 'next_url': url('accounts:achievements:group', self.achievement.group.slug) })
def test_add_achievements__all_accounts__not_remove_already_received_achievements(self): self.account_achievements_1.achievements.add_achievement(self.achievement_3) self.account_achievements_1.save() GiveAchievementTaskPrototype.create(account_id=None, achievement_id=self.achievement_3.id) account_achievements_2 = AccountAchievementsPrototype.get_by_account_id(self.account_2.id) self.assertTrue(self.account_achievements_1.has_achievement(self.achievement_3)) self.assertFalse(account_achievements_2.has_achievement(self.achievement_3)) with self.check_not_changed(MessagePrototype._db_count): self.worker.add_achievements() self.account_achievements_1.reload() account_achievements_2.reload() self.assertTrue(self.account_achievements_1.has_achievement(self.achievement_3)) self.assertFalse(account_achievements_2.has_achievement(self.achievement_3)) self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
def test_add_achievements__all_accounts(self): GiveAchievementTaskPrototype.create(account_id=None, achievement_id=self.achievement_3.id) account_achievements_2 = AccountAchievementsPrototype.get_by_account_id(self.account_2.id) self.assertFalse(self.account_achievements_1.has_achievement(self.achievement_3)) self.assertFalse(account_achievements_2.has_achievement(self.achievement_3)) hero = heroes_logic.load_hero(account_id=self.account_1.id) hero.statistics.change_pve_deaths(self.achievement_3.barrier) heroes_logic.save_hero(hero) with self.check_not_changed(MessagePrototype._db_count): self.worker.add_achievements() self.account_achievements_1.reload() account_achievements_2.reload() self.assertTrue(self.account_achievements_1.has_achievement(self.achievement_3)) self.assertFalse(account_achievements_2.has_achievement(self.achievement_3)) self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
def update(self): form = EditAchievementForm(self.request.POST) if not form.is_valid(): return self.json_error('accounts.achievements.update.form_errors', form.errors) with transaction.atomic(): is_changed = (self.achievement.type != form.c.type or self.achievement.approved != form.c.approved or self.achievement.barrier != form.c.barrier or self.achievement.points != form.c.points or self.achievement.item_1 != form.c.item_1 or self.achievement.item_2 != form.c.item_2 or self.achievement.item_3 != form.c.item_3 ) self.achievement.group = form.c.group self.achievement.type = form.c.type self.achievement.caption = form.c.caption self.achievement.description = form.c.description self.achievement.approved = form.c.approved self.achievement.barrier = form.c.barrier self.achievement.points = form.c.points self.achievement.order = form.c.order self.achievement.item_1_id = form.c.item_1.id if form.c.item_1 is not None else None self.achievement.item_2_id = form.c.item_2.id if form.c.item_2 is not None else None self.achievement.item_3_id = form.c.item_3.id if form.c.item_3 is not None else None self.achievement.save() if is_changed: GiveAchievementTaskPrototype.create(account_id=None, achievement_id=self.achievement.id) return self.json_ok(data={'next_url': url('accounts:achievements:group', self.achievement.group.slug)})
def test_legendary_achievements(self): achievement_4 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.LEGENDS, type=ACHIEVEMENT_TYPE.LEGENDS, barrier=0, points=0, caption=u'achievement_4', description=u'description_4', approved=True) self.account_achievements_1.achievements.add_achievement(achievement_4) self.account_achievements_1.save() GiveAchievementTaskPrototype.create(account_id=None, achievement_id=achievement_4.id) account_achievements_2 = AccountAchievementsPrototype.get_by_account_id(self.account_2.id) self.assertTrue(self.account_achievements_1.has_achievement(achievement_4)) self.assertFalse(account_achievements_2.has_achievement(achievement_4)) with self.check_not_changed(MessagePrototype._db_count): self.worker.add_achievements() self.account_achievements_1.reload() account_achievements_2.reload() self.assertTrue(self.account_achievements_1.has_achievement(achievement_4)) self.assertFalse(account_achievements_2.has_achievement(achievement_4)) self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)