Exemplo n.º 1
0
 def setUp(self):
     super(QotdTestCase, self).setUp()
     self.user, new = User.objects.get_or_create(username='******')
     self.user.save()
     profile = self.user.get_profile()
     self.qotd_user = profile.get_extension(QotdUser)
     scoring.setup_scoring()
Exemplo n.º 2
0
 def setUp(self):
     super(QuestStatistics, self).setUp()
     self.user1 = User.objects.create(username='******')
     self.user1.set_password('test')
     self.user1.save()
     self.quest_user1 = self.user1.get_profile().get_extension(QuestUser)
     self.user2 = User.objects.create(username='******')
     self.user2.set_password('test')
     self.user2.save()
     self.quest_user2 = self.user2.get_profile().get_extension(QuestUser)
     scoring.setup_scoring()
     category = Category.add('quest')
     question1 = Question.objects.create(text='question1',
                                         answer_type='F',
                                         category=category,
                                         active=True)
     answer1 = Answer.objects.create(text='first answer',
                                     correct=True,
                                     question=question1)
     question2 = Question.objects.create(text='question2',
                                         answer_type='F',
                                         category=category,
                                         active=True)
     answer2 = Answer.objects.create(text='second answer',
                                     correct=True,
                                     question=question2)
     start = datetime.datetime.now()
     end = datetime.datetime.now() + timedelta(days=1)
     self.quest = Quest.objects.create(start=start, end=end)
     self.quest.questions.add(question1)
     self.quest.questions.add(question2)
Exemplo n.º 3
0
 def setUp(self):
     user_from = self._get_player(1)
     user_to = self._get_player(2)
     chall_user1 = user_from.get_extension(ChallengeUser)
     chall_user2 = user_to.get_extension(ChallengeUser)
     scoring.setup_scoring()
     self.chall = Challenge.create(user_from=chall_user1, user_to=chall_user2, ignore_questions=True)
Exemplo n.º 4
0
 def setUp(self):
     super(QotdTestCase, self).setUp()
     self.user, new = User.objects.get_or_create(username='******')
     self.user.save()
     profile = self.user.get_profile()
     self.qotd_user = profile.get_extension(QotdUser)
     scoring.setup_scoring()
Exemplo n.º 5
0
    def setUp(self):
        super(TestChallengeViews, self).setUp()
        self.ch_player1 = self._get_player(1)
        self.ch_player2 = self._get_player(2)
        race = Race.objects.create(name=u'testrace', can_play=True)
        self.ch_player1.race = race
        self.ch_player2.race = race
        self.ch_player1.points = 100
        self.ch_player2.points = 100
        self.ch_player1.save()
        self.ch_player2.save()
        self.ch_player1 = self.ch_player1.get_extension(ChallengeUser)
        self.ch_player2 = self.ch_player2.get_extension(ChallengeUser)
        scoring.setup_scoring()

        self.category = Category.add('challenge')
        self.question1 = Question.objects.create(text='question1', answer_type='F',
                                                 category=self.category, active=True)
        self.answer1 = Answer.objects.create(text='first answer', correct=True,
                                             question=self.question1)
        self.question2 = Question.objects.create(text='question2', answer_type='F',
                                                 category=self.category, active=True)
        self.answer2 = Answer.objects.create(text='second answer', correct=True,
                                             question=self.question2)
        self.ch = Challenge.create(user_from=self.ch_player1, user_to=self.ch_player2,
                        ignore_questions=True)
        self.ch.questions.add(self.question1)
        self.ch.questions.add(self.question2)

        self.c = Client()
        self.c.login(username='******', password='******')
Exemplo n.º 6
0
    def setUp(self):
        super(TestChallengeViews, self).setUp()
        self.ch_player1 = self._get_player(1)
        self.ch_player2 = self._get_player(2)
        race = Race.objects.create(name=u'testrace', can_play=True)
        self.ch_player1.race = race
        self.ch_player2.race = race
        self.ch_player1.points = 100
        self.ch_player2.points = 100
        self.ch_player1.save()
        self.ch_player2.save()
        self.ch_player1 = self.ch_player1.get_extension(ChallengeUser)
        self.ch_player2 = self.ch_player2.get_extension(ChallengeUser)
        scoring.setup_scoring()

        self.category = Category.add('challenge')
        self.question1 = Question.objects.create(text='question1', answer_type='F',
                                                 category=self.category, active=True)
        self.answer1 = Answer.objects.create(text='first answer', correct=True,
                                             question=self.question1)
        self.question2 = Question.objects.create(text='question2', answer_type='F',
                                                 category=self.category, active=True)
        self.answer2 = Answer.objects.create(text='second answer', correct=True,
                                             question=self.question2)
        self.ch = Challenge.create(user_from=self.ch_player1, user_to=self.ch_player2,
                        ignore_questions=True)
        self.ch.questions.add(self.question1)
        self.ch.questions.add(self.question2)

        self.c = Client()
        self.c.login(username='******', password='******')
Exemplo n.º 7
0
    def test_charge(self):
        """
         Test for Charge spell
        """
        initial_points = 10

        player = self._get_player()
        player2 = self._get_player(2)
        chall_user = player.get_extension(ChallengeUser)

        scoring.setup_scoring()
        Coin.add('points')
        scoring.score_simple(chall_user, 'points', initial_points)
        self.assertEqual(player.points, initial_points)

        # Points won before Charge is applied
        chall = Challenge.create(user_from=chall_user, user_to=player2, ignore_questions=True)
        chall.set_won_by_player(chall_user)
        points_no_charge = player.points

        # Apply Charge
        charge = Spell.objects.create(name='challenge-affect-scoring', available=True, price=10, percents=33, type='p')
        obs = PlayerSpellDue.objects.create(player=chall_user, source=chall_user, spell=charge, due=datetime.now() + timedelta(days=1))
        self.assertTrue(chall_user.magic.has_modifier('challenge-affect-scoring'))

        player.points = initial_points
        chall = Challenge.create(user_from=chall_user, user_to=player2, ignore_questions=True)
        chall.set_won_by_player(chall_user)

        # Player should have 33% more points with charge applied
        self.assertEqual(player.points, points_no_charge + 0.33 * (points_no_charge - initial_points))
Exemplo n.º 8
0
    def test_weakness_and_charge(self):
        """
         If both Weakness and Charge are active, a player should win weakness.percents + charge.percents less/more points
         after winning a challenge
        """
        initial_points = 100
        win_points = 10

        player = self._get_player(1).get_extension(ChallengeUser)
        player_dummy = self._get_player(2).get_extension(ChallengeUser)

        scoring.setup_scoring()
        Coin.add('points')
        scoring.score_simple(player, 'points', initial_points)

        formula = Formula.get('chall-won')
        formula.expression = 'points=' + str(win_points)
        formula.save()

        # Apply charge
        charge = Spell.objects.create(name='challenge-affect-scoring-won', available=True, price=10, percents=33, type='p')
        obs = PlayerSpellDue.objects.create(player=player, source=player, spell=charge, due=datetime.now() + timedelta(days=1))

        # Apply weakness
        weakness = Spell.objects.create(name='challenge-affect-scoring-won', available=True, price=10, percents=-66, type='p')
        obs = PlayerSpellDue.objects.create(player=player, source=player, spell=weakness, due=datetime.now() + timedelta(days=1))

        chall = Challenge.create(user_from=player, user_to=player_dummy, ignore_questions=True)
        chall.set_won_by_player(player)

        percents = (charge.percents + weakness.percents) / 100.0
        target_points = initial_points + win_points + percents * win_points

        self.assertEqual(player.player_ptr.points, target_points)
Exemplo n.º 9
0
    def test_weakness(self):
        """
         Test for weakness
        """

        initial_points = 10

        player = self._get_player()
        player2 = self._get_player(2)
        chall_user = player.get_extension(ChallengeUser)

        scoring.setup_scoring()
        Coin.add('points')
        scoring.score_simple(chall_user, 'points', initial_points)
        self.assertEqual(player.points, initial_points)

        # Points won before Weakness is applied
        chall = Challenge.create(user_from=chall_user, user_to=player2, ignore_questions=True)
        chall.set_won_by_player(chall_user)
        points_no_weakness = player.points

        # Applying Weakness
        weakness = Spell.objects.create(name='challenge-affect-scoring', available=True, price=10, percents=-66, type='n')
        obs = PlayerSpellDue.objects.create(player=chall_user, source=chall_user, spell=weakness, due=datetime.now() + timedelta(days=1))
        self.assertTrue(chall_user.magic.has_modifier('challenge-affect-scoring'))

        player.points = initial_points
        chall = Challenge.create(user_from=chall_user, user_to=player2, ignore_questions=True)
        chall.set_won_by_player(chall_user)

        # Player should win 66% less points with weakness applied
        self.assertEqual(player.points, points_no_weakness - 0.66 * (points_no_weakness - initial_points))
Exemplo n.º 10
0
    def test_blind(self):
        """
        Test for Blind spell
        """

        # Create a question and a test user
        super_user = self._get_superuser()
        qotd_user = self._get_player(1)
        qotd_user = qotd_user.get_extension(QotdUser)
        scoring.setup_scoring()

        question = _make_question_for_today(super_user, 'question1')

        c = Client()
        c.login(username='******', password='******')

        # Cast blind on qotd_user
        blind = Spell.objects.create(name='qotd-blind',
                                     available=True,
                                     price=10,
                                     type='n')
        PlayerSpellDue.objects.create(player=qotd_user,
                                      source=qotd_user,
                                      spell=blind,
                                      due=datetime.now() + timedelta(days=1))
        self.assertTrue(qotd_user.magic.has_modifier('qotd-blind'))

        # Check if it blocks the user from answering the Question of the Day
        response = c.get(reverse('qotd_index_view'), follow=True)
        self.assertContains(
            response,
            "You have been blinded, you cannot answer to the Question of the Day"
        )
Exemplo n.º 11
0
    def test_scoring_loss(self):
        initial_points = 10
        winner = self._get_player(1).get_extension(ChallengeUser)
        loser = self._get_player(2).get_extension(ChallengeUser)

        # Setup scoring
        scoring.setup_scoring()
        Coin.add('points')

        # Give initial points
        scoring.score_simple(winner, 'points', initial_points)
        scoring.score_simple(loser, 'points', initial_points)

        # Set formula
        loss_points = -2
        formula = Formula.get('chall-lost')
        formula.expression = 'points=' + str(loss_points)
        formula.save()

        # Play challenge
        chall = Challenge.create(user_from=winner,
                                 user_to=loser,
                                 ignore_questions=True)
        chall.set_won_by_player(winner)

        self.assertEqual(loser.player_ptr.points, initial_points +
                         loss_points)  # loss_points is negative
Exemplo n.º 12
0
    def test_charge(self):
        """
         Test for Charge spell
        """
        initial_points = 100
        win_points = 10

        player_charge = self._get_player(1).get_extension(ChallengeUser)
        player_dummy = self._get_player(2).get_extension(ChallengeUser)

        scoring.setup_scoring()
        Coin.add('points')
        scoring.score_simple(player_charge, 'points', initial_points)

        formula = Formula.get('chall-won')
        formula.expression = 'points=' + str(win_points)
        formula.save()

        # Apply charge
        charge = Spell.objects.create(name='challenge-affect-scoring-won', available=True, price=10, percents=33, type='p')
        obs = PlayerSpellDue.objects.create(player=player_charge, source=player_charge, spell=charge, due=datetime.now() + timedelta(days=1))

        chall = Challenge.create(user_from=player_charge, user_to=player_dummy, ignore_questions=True)
        chall.set_won_by_player(player_charge)

        # Player should win weakness.percents more points with charge applied
        target_points = initial_points + win_points + charge.percents / 100.0 * win_points
        self.assertEqual(player_charge.player_ptr.points, target_points)
Exemplo n.º 13
0
    def test_frenzy_loss(self):
        """
         If user loses while affected by frenzy he should lose frenzy.percents more points
        """
        initial_points = 100
        loss_points = -10
        warranty_points = -3

        player_frenzy = self._get_player(1).get_extension(ChallengeUser)
        player_dummy = self._get_player(2).get_extension(ChallengeUser)

        scoring.setup_scoring()
        Coin.add('points')
        scoring.score_simple(player_frenzy, 'points', initial_points)

        formula = Formula.get('chall-lost')
        formula.expression = 'points=' + str(loss_points)
        formula.save()

        formula = Formula.get('chall-warranty')
        formula.expression = 'points=' + str(warranty_points)
        formula.save()

        # Apply frenzy
        frenzy = Spell.objects.create(name='challenge-affect-scoring', available=True, price=25, percents=66, type='o')
        obs = PlayerSpellDue.objects.create(player=player_frenzy, source=player_frenzy, spell=frenzy, due=datetime.now() + timedelta(days=1))

        # Win challenge with dummy player to see the amount of points lost by the player affected with frenzy
        chall = Challenge.create(user_from=player_frenzy, user_to=player_dummy, ignore_questions=True)
        chall.set_won_by_player(player_dummy)

        # Player should lose frenzy.percents more points with frenzy applied
        target_points = initial_points + loss_points + frenzy.percents / 100.0 * loss_points + warranty_points

        self.assertEqual(player_frenzy.player_ptr.points, target_points)
Exemplo n.º 14
0
 def setUp(self):
     self.user = User.objects.create(username='******')
     self.user.save()
     self.chall_user = self.user.get_profile().get_extension(ChallengeUser)
     self.user2 = User.objects.create(username='******')
     self.user2.save()
     self.chall_user2 = self.user2.get_profile().get_extension(ChallengeUser)
     scoring.setup_scoring()
Exemplo n.º 15
0
 def setUp(self):
     self.user = User.objects.create(username='******')
     self.user.set_password('_test_pw')
     self.user.save()
     profile = self.user.get_profile()
     self.qotd_user = profile.get_extension(QotdUser)
     scoring.setup_scoring()
     self.client.login(username='******', password='******')
Exemplo n.º 16
0
 def setUp(self):
     super(FlawlessVictoryTest, self).setUp()
     self.user_from = self._get_player(1)
     self.user_to   = self._get_player(2)
     self.chall_user1 = self.user_from.get_extension(ChallengeUser)
     self.chall_user2 = self.user_to.get_extension(ChallengeUser)
     scoring.setup_scoring()
     self.chall = Challenge.create(user_from=self.chall_user1, user_to=self.chall_user2, ignore_questions=True)
Exemplo n.º 17
0
 def setUp(self):
     self.user = User.objects.create(username='******')
     self.user.set_password('_test_pw')
     self.user.save()
     profile = self.user.get_profile()
     self.qotd_user = profile.get_extension(QotdUser)
     scoring.setup_scoring()
     self.client.login(username='******', password='******')
Exemplo n.º 18
0
    def handle(self, *args, **options):
        save_load_labels = ['magic', 'scoring.coin', 'scoring.formula', 'config', 'pages', 'user.race', 'user.playergroup']
        reset_labels = ['magic', 'scoring', 'config', 'pages']
        if options['check_setup']:
            ok = True
            # Check scoring
            if not check_setup():
                self.stdout.write('FAIL: Scoring module not setup.')
                ok = False

            if ok:
                self.stdout.write('OK.\n')

        elif options['setup']:
            if options['noinput']:
                # YOLO: call_command does not work if I call the syncdb command
                # with the 'all' parameter, so we use subprocess
                subprocess.call(['python', 'manage.py', 'syncdb', '--all',
                                 '--noinput'])
            else:
                subprocess.call(['python', 'manage.py', 'syncdb', '--all'])
            # Call migrations as fake because some conflicts after moving to
            # South
            call_command('migrate', fake=True)
            # Call migrations here, because we want fixtures to be loaded
            call_command('migrate')

            self.stdout.write('Setting up scoring...')
            setup_scoring()
            self.stdout.write('\n')
            self.stdout.write('Setting up user groups...')
            setup_user_groups()
            setup_staff_groups()
            self.stdout.write('\n')
            self.stdout.write('Setting up magic...')
            setup_magic()
            self.stdout.write('\n')
            self.stdout.write('Done.\n')

        elif options['save']:
            c = DumpdataCommand()
            with open(options['save'], 'w') as fout:
                data = c.handle(*save_load_labels, **options)
                fout.write(data)
            self.stdout.write('Saved!\n')

        elif options['load']:
            call_command('loaddata', options['load'])
            self.stdout.write('Loaded!\n')

        elif options['reset']:
            call_command('sqlreset', *reset_labels)

        elif options['updatedisplay']:
            update_all_display_names()

        else:
            self.print_help('wousoctl', '')
Exemplo n.º 19
0
 def setUp(self):
     user_from = self._get_player(1)
     user_to = self._get_player(2)
     chall_user1 = user_from.get_extension(ChallengeUser)
     chall_user2 = user_to.get_extension(ChallengeUser)
     scoring.setup_scoring()
     self.chall = Challenge.create(user_from=chall_user1,
                                   user_to=chall_user2,
                                   ignore_questions=True)
Exemplo n.º 20
0
 def setUp(self):
     self.user = User.objects.create(username='******')
     self.user.save()
     self.chall_user = self.user.get_profile().get_extension(ChallengeUser)
     self.user2 = User.objects.create(username='******')
     self.user2.save()
     self.chall_user2 = self.user2.get_profile().get_extension(
         ChallengeUser)
     scoring.setup_scoring()
Exemplo n.º 21
0
 def setUp(self):
     super(FlawlessVictoryTest, self).setUp()
     self.user_from = self._get_player(1)
     self.user_to = self._get_player(2)
     self.chall_user1 = self.user_from.get_extension(ChallengeUser)
     self.chall_user2 = self.user_to.get_extension(ChallengeUser)
     scoring.setup_scoring()
     self.chall = Challenge.create(user_from=self.chall_user1,
                                   user_to=self.chall_user2,
                                   ignore_questions=True)
Exemplo n.º 22
0
 def setUp(self):
     super(ChallengeTestCase, self).setUp()
     self.user = User.objects.create(username='******')
     self.user.save()
     self.chall_user = self.user.get_profile().get_extension(ChallengeUser)
     self.user2 = User.objects.create(username='******')
     self.user2.save()
     self.chall_user2 = self.user2.get_profile().get_extension(ChallengeUser)
     scoring.setup_scoring()
     ChallengeGame.get_instance().save()
Exemplo n.º 23
0
 def setUp(self):
     super(ChallengeTestCase, self).setUp()
     self.user = User.objects.create(username='******')
     self.user.save()
     self.chall_user = self.user.get_profile().get_extension(ChallengeUser)
     self.user2 = User.objects.create(username='******')
     self.user2.save()
     self.chall_user2 = self.user2.get_profile().get_extension(ChallengeUser)
     scoring.setup_scoring()
     ChallengeGame.get_instance().save()
Exemplo n.º 24
0
    def setUp(self):
        super(TestQotdViews, self).setUp()
        self.super_user = self._get_superuser()
        self.qotd_user = self._get_player(1)
        self.qotd_user = self.qotd_user.get_extension(QotdUser)
        scoring.setup_scoring()

        self.question = _make_question_for_today(self.super_user, 'question1')

        self.c = Client()
        self.c.login(username='******', password='******')
Exemplo n.º 25
0
    def handle(self, *args, **options):
        save_load_labels = [
            'magic', 'scoring.coin', 'scoring.formula', 'config', 'pages',
            'user.race', 'user.playergroup'
        ]
        reset_labels = ['magic', 'scoring', 'config', 'pages']
        if options['check_setup']:
            ok = True
            # Check scoring
            if not check_setup():
                self.stdout.write('FAIL: Scoring module not setup.')
                ok = False

            if ok:
                self.stdout.write('OK.\n')

        elif options['setup']:
            if options['noinput']:
                call_command('syncdb', interactive=False)
            else:
                call_command('syncdb')
            call_command('migrate')

            self.stdout.write('Setting up scoring...')
            setup_scoring()
            self.stdout.write('\n')
            self.stdout.write('Setting up user groups...')
            setup_user_groups()
            setup_staff_groups()
            self.stdout.write('\n')
            self.stdout.write('Setting up magic...')
            setup_magic()
            self.stdout.write('\n')
            self.stdout.write('Done.\n')

        elif options['save']:
            c = DumpdataCommand()
            with open(options['save'], 'w') as fout:
                data = c.handle(*save_load_labels, **options)
                fout.write(data)
            self.stdout.write('Saved!\n')

        elif options['load']:
            call_command('loaddata', options['load'])
            self.stdout.write('Loaded!\n')

        elif options['reset']:
            call_command('sqlreset', *reset_labels)

        elif options['updatedisplay']:
            update_all_display_names()

        else:
            self.print_help('wousoctl', '')
Exemplo n.º 26
0
    def setUp(self):
        super(TestQotdViews, self).setUp()
        self.super_user = self._get_superuser()
        self.qotd_user = self._get_player(1)
        self.qotd_user = self.qotd_user.get_extension(QotdUser)
        scoring.setup_scoring()

        self.question = _make_question_for_today(self.super_user, 'question1')

        self.c = Client()
        self.c.login(username='******', password='******')
Exemplo n.º 27
0
    def test_evade(self):
        """
         Test for Evade spell
        """
        player = self._get_player()
        player2 = self._get_player(2)

        initial_points = 10

        scoring.setup_scoring()
        Coin.add('points')
        scoring.score_simple(player, 'points', initial_points)
        self.assertEqual(player.points, initial_points)

        # Create and apply evade
        evade = Spell.objects.create(name='challenge-evade',
                                     available=True,
                                     price=25,
                                     percents=100,
                                     type='p')
        obs = PlayerSpellDue.objects.create(player=player,
                                            source=player,
                                            spell=evade,
                                            due=datetime.now() +
                                            timedelta(days=1))
        self.assertTrue(player.magic.has_modifier('challenge-evade'))

        # Get 'chall-lost' expression. By default you still win 2 points when losing a challenge
        formulas = ChallengeGame.get_formulas()
        exp = formulas[1]['expression']  # this will be 'points=XX'
        index = exp.find('=') + 1  # get position of '='
        points = int(
            exp[index:])  # get XX (nr of points won when losing challenge)

        # Create challenge and make first player lose it
        chall = Challenge.create(user_from=player2,
                                 user_to=player,
                                 ignore_questions=True)
        chall.set_won_by_player(player2)

        # If evade spell worked losing player should have initial_points + 'chall-lost' points

        # Evade has 20% chance of activation so play challenge in loop while it activates
        while player.points != initial_points + points:
            player.points = initial_points
            chall.set_expired()
            chall = Challenge.create(user_from=player2,
                                     user_to=player,
                                     ignore_questions=True)
            chall.set_won_by_player(player2)

        # Check if final score is ok
        self.assertEqual(player.points, initial_points + points)
Exemplo n.º 28
0
    def test_weakness_and_charge(self):
        """
         If both Weakness and Charge are active, a player should win weakness.percents + charge.percents less/more points
         after winning a challenge
        """
        initial_points = 100
        win_points = 10

        player = self._get_player(1).get_extension(ChallengeUser)
        player_dummy = self._get_player(2).get_extension(ChallengeUser)

        scoring.setup_scoring()
        Coin.add('points')
        scoring.score_simple(player, 'points', initial_points)

        formula = Formula.get('chall-won')
        formula.expression = 'points=' + str(win_points)
        formula.save()

        # Apply charge
        charge = Spell.objects.create(name='challenge-affect-scoring-won',
                                      available=True,
                                      price=10,
                                      percents=33,
                                      type='p')
        obs = PlayerSpellDue.objects.create(player=player,
                                            source=player,
                                            spell=charge,
                                            due=datetime.now() +
                                            timedelta(days=1))

        # Apply weakness
        weakness = Spell.objects.create(name='challenge-affect-scoring-won',
                                        available=True,
                                        price=10,
                                        percents=-66,
                                        type='p')
        obs = PlayerSpellDue.objects.create(player=player,
                                            source=player,
                                            spell=weakness,
                                            due=datetime.now() +
                                            timedelta(days=1))

        chall = Challenge.create(user_from=player,
                                 user_to=player_dummy,
                                 ignore_questions=True)
        chall.set_won_by_player(player)

        percents = (charge.percents + weakness.percents) / 100.0
        target_points = initial_points + win_points + percents * win_points

        self.assertEqual(player.player_ptr.points, target_points)
Exemplo n.º 29
0
    def test_cache_points(self):
        scoring.setup_scoring()
        Challenge.WARRANTY = True
        p1, p2 = self._get_player(1), self._get_player(2)

        initial_points = p1.points
        challenge = Challenge.create(p1, p2, ignore_questions=True)
        p1 = Player.objects.get(pk=p1.pk)
        self.assertNotEqual(p1.points, initial_points)
        self.assertTrue(challenge)
        challenge.refuse()
        p1 = p1.user.get_profile()
        self.assertEqual(p1.points, initial_points)
Exemplo n.º 30
0
    def test_cache_points(self):
        scoring.setup_scoring()
        Challenge.WARRANTY = True
        p1, p2 = self._get_player(1), self._get_player(2)

        initial_points = p1.points
        challenge = Challenge.create(p1, p2, ignore_questions=True)
        p1 = Player.objects.get(pk=p1.pk)
        self.assertNotEqual(p1.points, initial_points)
        self.assertTrue(challenge)
        challenge.refuse()
        p1 = p1.user.get_profile()
        self.assertEqual(p1.points, initial_points)
Exemplo n.º 31
0
 def setUp(self):
     super(TestMagicViews, self).setUp()
     self.p1 = self._get_player(1)
     self.p2 = self._get_player(2)
     self.p1.points = 500
     self.p1.save()
     self.spell_1 = Spell.objects.create(name='spell1', title='Spell no. 1')
     self.spell_2 = Spell.objects.create(name='spell2', title='Spell no. 2')
     self.c = Client()
     self.c.login(username='******', password='******')
     self.activity = Activity.objects.create(user_from=self.p1, user_to=self.p2,
                                             action='gold-won')
     scoring.setup_scoring()
Exemplo n.º 32
0
    def handle(self, *args, **options):
        save_load_labels = ['magic', 'scoring.coin', 'scoring.formula', 'config', 'pages', 'user.race', 'user.playergroup']
        reset_labels = ['magic', 'scoring', 'config', 'pages']
        if options['check_setup']:
            ok = True
            # Check scoring
            if not check_setup():
                self.stdout.write('FAIL: Scoring module not setup.')
                ok = False

            if ok:
                self.stdout.write('OK.\n')

        elif options['setup']:
            if options['noinput']:
                call_command('syncdb', interactive=False)
            else:
                call_command('syncdb')
            call_command('migrate')

            self.stdout.write('Setting up scoring...')
            setup_scoring()
            self.stdout.write('\n')
            self.stdout.write('Setting up user groups...')
            setup_user_groups()
            setup_staff_groups()
            self.stdout.write('\n')
            self.stdout.write('Setting up magic...')
            setup_magic()
            self.stdout.write('\n')
            self.stdout.write('Done.\n')

        elif options['save']:
            c = DumpdataCommand()
            with open(options['save'], 'w') as fout:
                data = c.handle(*save_load_labels, **options)
                fout.write(data)
            self.stdout.write('Saved!\n')

        elif options['load']:
            call_command('loaddata', options['load'])
            self.stdout.write('Loaded!\n')

        elif options['reset']:
            call_command('sqlreset', *reset_labels)

        elif options['updatedisplay']:
            update_all_display_names()

        else:
            self.print_help('wousoctl', '')
Exemplo n.º 33
0
 def setUp(self):
     super(TestQuestViews, self).setUp()
     self.admin = self._get_superuser()
     self.c = Client()
     self.c.login(username='******', password='******')
     now = datetime.datetime.now()
     Quest.objects.create(start=now-timedelta(days=2), end=now-timedelta(days=1),
                          title='Quest no. 1')
     self.q = Quest.objects.create(start=now, end=now + timedelta(days=1),
                          title='Quest no. 2')
     Quest.objects.create(start=now+timedelta(days=1), end=now + timedelta(days=2),
                          title='Quest no. 3')
     FinalQuest.objects.create(start=now, end=now+timedelta(days=1),
                               title='Final Quest')
     scoring.setup_scoring()
Exemplo n.º 34
0
    def test_frenzy_loss(self):
        """
         If user loses while affected by frenzy he should lose frenzy.percents more points
        """
        initial_points = 100
        loss_points = -10
        warranty_points = -3

        player_frenzy = self._get_player(1).get_extension(ChallengeUser)
        player_dummy = self._get_player(2).get_extension(ChallengeUser)

        scoring.setup_scoring()
        Coin.add('points')
        scoring.score_simple(player_frenzy, 'points', initial_points)

        formula = Formula.get('chall-lost')
        formula.expression = 'points=' + str(loss_points)
        formula.save()

        formula = Formula.get('chall-warranty')
        formula.expression = 'points=' + str(warranty_points)
        formula.save()

        # Apply frenzy
        frenzy = Spell.objects.create(name='challenge-affect-scoring',
                                      available=True,
                                      price=25,
                                      percents=66,
                                      type='o')
        obs = PlayerSpellDue.objects.create(player=player_frenzy,
                                            source=player_frenzy,
                                            spell=frenzy,
                                            due=datetime.now() +
                                            timedelta(days=1))

        # Win challenge with dummy player to see the amount of points lost by the player affected with frenzy
        chall = Challenge.create(user_from=player_frenzy,
                                 user_to=player_dummy,
                                 ignore_questions=True)
        chall.set_won_by_player(player_dummy)

        # Player should lose frenzy.percents more points with frenzy applied
        target_points = initial_points + loss_points + frenzy.percents / 100.0 * loss_points + warranty_points

        self.assertEqual(player_frenzy.player_ptr.points, target_points)
Exemplo n.º 35
0
 def setUp(self):
     super(TestQuestViews, self).setUp()
     self.admin = self._get_superuser()
     self.c = Client()
     self.c.login(username='******', password='******')
     now = datetime.datetime.now()
     Quest.objects.create(start=now - timedelta(days=2),
                          end=now - timedelta(days=1),
                          title='Quest no. 1')
     self.q = Quest.objects.create(start=now,
                                   end=now + timedelta(days=1),
                                   title='Quest no. 2')
     Quest.objects.create(start=now + timedelta(days=1),
                          end=now + timedelta(days=2),
                          title='Quest no. 3')
     FinalQuest.objects.create(start=now,
                               end=now + timedelta(days=1),
                               title='Final Quest')
     scoring.setup_scoring()
Exemplo n.º 36
0
    def test_evade(self):
        """
         Test for Evade spell
        """
        player = self._get_player()
        player2 = self._get_player(2)

        initial_points = 10

        scoring.setup_scoring()
        Coin.add('points')
        scoring.score_simple(player, 'points', initial_points)
        self.assertEqual(player.points, initial_points)

        # Create and apply evade
        evade = Spell.objects.create(name='challenge-evade', available=True, price=25, percents=100, type='p')
        obs = PlayerSpellDue.objects.create(player=player, source=player, spell=evade, due=datetime.now() + timedelta(days=1))
        self.assertTrue(player.magic.has_modifier('challenge-evade'))

        # Get 'chall-lost' expression. By default you still win 2 points when losing a challenge
        formulas = ChallengeGame.get_formulas()
        exp = formulas[1]['expression'] # this will be 'points=XX'
        index = exp.find('=') + 1 # get position of '='
        points = int(exp[index:]) # get XX (nr of points won when losing challenge)

        # Create challenge and make first player lose it
        chall = Challenge.create(user_from=player2, user_to=player, ignore_questions=True)
        chall.set_won_by_player(player2)

        # If evade spell worked losing player should have initial_points + 'chall-lost' points

        # Evade has 20% chance of activation so play challenge in loop while it activates
        while player.points != initial_points + points:
            player.points = initial_points
            chall.set_expired()
            chall = Challenge.create(user_from=player2, user_to=player, ignore_questions=True)
            chall.set_won_by_player(player2)

        # Check if final score is ok
        self.assertEqual(player.points, initial_points + points)
Exemplo n.º 37
0
    def test_weakness(self):
        """
         Test for Weakness spell
        """
        initial_points = 100
        win_points = 10

        player_weakness = self._get_player(1).get_extension(ChallengeUser)
        player_dummy = self._get_player(2).get_extension(ChallengeUser)

        scoring.setup_scoring()
        Coin.add('points')
        scoring.score_simple(player_weakness, 'points', initial_points)

        formula = Formula.get('chall-won')
        formula.expression = 'points=' + str(win_points)
        formula.save()

        # Apply weakness
        weakness = Spell.objects.create(name='challenge-affect-scoring-lost',
                                        available=True,
                                        price=10,
                                        percents=-66,
                                        type='n')
        obs = PlayerSpellDue.objects.create(player=player_weakness,
                                            source=player_weakness,
                                            spell=weakness,
                                            due=datetime.now() +
                                            timedelta(days=1))

        # Win challenge with player_weakness
        chall = Challenge.create(user_from=player_weakness,
                                 user_to=player_dummy,
                                 ignore_questions=True)
        chall.set_won_by_player(player_weakness)

        # Player should win weakness.percents less points with weakness applied
        target_points = initial_points + win_points + weakness.percents / 100.0 * win_points
        self.assertEqual(player_weakness.player_ptr.points, target_points)
Exemplo n.º 38
0
 def setUp(self):
     super(QuestStatistics, self).setUp()
     self.user1 = User.objects.create(username='******')
     self.user1.set_password('test')
     self.user1.save()
     self.quest_user1 = self.user1.get_profile().get_extension(QuestUser)
     self.user2 = User.objects.create(username='******')
     self.user2.set_password('test')
     self.user2.save()
     self.quest_user2 = self.user2.get_profile().get_extension(QuestUser)
     scoring.setup_scoring()
     category = Category.add('quest')
     question1 = Question.objects.create(text='question1', answer_type='F',
                                        category=category, active=True)
     answer1 = Answer.objects.create(text='first answer', correct=True, question=question1)
     question2 = Question.objects.create(text='question2', answer_type='F',
                                        category=category, active=True)
     answer2 = Answer.objects.create(text='second answer', correct=True, question=question2)
     start = datetime.datetime.now()
     end = datetime.datetime.now() + timedelta(days=1)
     self.quest = Quest.objects.create(start=start, end=end)
     self.quest.questions.add(question1)
     self.quest.questions.add(question2)
Exemplo n.º 39
0
    def test_blind(self):
        """
        Test for Blind spell
        """

        # Create a question and a test user
        super_user = self._get_superuser()
        qotd_user = self._get_player(1)
        qotd_user = qotd_user.get_extension(QotdUser)
        scoring.setup_scoring()

        question = _make_question_for_today(super_user, 'question1')

        c = Client()
        c.login(username='******', password='******')

        # Cast blind on qotd_user
        blind = Spell.objects.create(name='qotd-blind', available=True, price=10, type='n')
        PlayerSpellDue.objects.create(player=qotd_user, source=qotd_user, spell=blind, due=datetime.now() + timedelta(days=1))
        self.assertTrue(qotd_user.magic.has_modifier('qotd-blind'))

        # Check if it blocks the user from answering the Question of the Day
        response = c.get(reverse('qotd_index_view'), follow=True)
        self.assertContains(response, "You have been blinded, you cannot answer to the Question of the Day")
Exemplo n.º 40
0
    def test_scoring_loss(self):
        initial_points = 10
        winner = self._get_player(1).get_extension(ChallengeUser)
        loser = self._get_player(2).get_extension(ChallengeUser)

        # Setup scoring
        scoring.setup_scoring()
        Coin.add('points')

        # Give initial points
        scoring.score_simple(winner, 'points', initial_points)
        scoring.score_simple(loser, 'points', initial_points)

        # Set formula
        loss_points = -2
        formula = Formula.get('chall-lost')
        formula.expression = 'points=' + str(loss_points)
        formula.save()

        # Play challenge
        chall = Challenge.create(user_from=winner, user_to=loser, ignore_questions=True)
        chall.set_won_by_player(winner)

        self.assertEqual(loser.player_ptr.points, initial_points + loss_points) # loss_points is negative
Exemplo n.º 41
0
 def test_check_setup(self):
     self.assertFalse(check_setup())
     setup_scoring()
     self.assertTrue(check_setup())
Exemplo n.º 42
0
 def test_setup(self):
     for c in CORE_POINTS:
         self.assertFalse(Coin.get(c))
     setup_scoring()
     for c in CORE_POINTS:
         self.assertTrue(Coin.get(c))
Exemplo n.º 43
0
 def setUp(self):
     self.user, new = User.objects.get_or_create(username='******')
     self.user.save()
     profile = self.user.get_profile()
     self.quest_user = profile.get_extension(QuestUser)
     scoring.setup_scoring()
Exemplo n.º 44
0
 def setUp(self):
     self.user, new = User.objects.get_or_create(username='******')
     self.user.save()
     profile = self.user.get_profile()
     self.quest_user = profile.get_extension(QuestUser)
     scoring.setup_scoring()
Exemplo n.º 45
0
 def test_setup(self):
     for c in CORE_POINTS:
         self.assertFalse(Coin.get(c))
     setup_scoring()
     for c in CORE_POINTS:
         self.assertTrue(Coin.get(c))
Exemplo n.º 46
0
 def test_check_setup(self):
     self.assertFalse(check_setup())
     setup_scoring()
     self.assertTrue(check_setup())
Exemplo n.º 47
0
import sys
sys.path.append('..');sys.path.append('.')

from django.core.management import setup_environ
import settings
setup_environ(settings)

from wouso.core import scoring
from wouso.core.scoring.models import *

if __name__ == '__main__':
    print 'Setting up the Scoring module...',
    # TODO: i'm pretty sure this can be accomplished by simple fixtures.
    scoring.setup_scoring()
    print 'done!'

    # Dump
    print "Coins: "
    for c in Coin.objects.all():
        print " ", c
    print "Formulas: "
    for f in Formula.objects.all():
        print " ", f
Exemplo n.º 48
0
 def setUp(self):
     self.user, new = User.objects.get_or_create(username="******")
     self.user.save()
     profile = self.user.get_profile()
     self.qotd_user = profile.get_extension(QotdUser)
     scoring.setup_scoring()