def test_update_points_level_upgrade_first_time(self): level_up_points = 80 IntegerListSetting.get('level_limits').set_value(str(level_up_points)) Coin.add('points') Coin.add('gold') Formula.add('level-gold', expression='gold=10*{level}', owner=None) # Upgrade player's level player = self._get_player() player.points = level_up_points + 1 player.level_no = 1 player.save() update_points(player, None) coins = History.user_coins(player.user) self.assertEqual(coins['gold'], 10 * player.max_level)
def test_fibbonaci_formula(self): formula = Formula.add('test-fib', expression='points=fib(0)') value = calculate(formula)['points'] self.assertEqual(value, 0) formula.expression = 'points=fib(1)' formula.save() value = calculate(formula)['points'] self.assertEqual(value, 1) formula.expression = 'points=fib(2)' formula.save() value = calculate(formula)['points'] self.assertEqual(value, 1) formula.expression = 'points=fib(3)' formula.save() value = calculate(formula)['points'] self.assertEqual(value, 2) formula.expression = 'points=fib(4)' formula.save() value = calculate(formula)['points'] self.assertEqual(value, 3)
def testUpdatePoints(self): Coin.add('points') Coin.add('gold') Formula.add('level-gold', expression='gold=10*{level}', owner=None) player = self._get_player() player.points = 82 player.level_no = 1 player.save() update_points(player, None) coins = History.user_coins(player.user) self.assertIn('gold', coins) self.assertEqual(coins['gold'], 20) player.points = 10 player.save() update_points(player, None) coins = History.user_coins(player.user) self.assertIn('gold', coins) self.assertEqual(coins['gold'], 0)
def testUpdatePoints(self): Coin.add('points') Coin.add('gold') Formula.add('level-gold', definition='gold=10*{level}', owner=None) player = self._get_player() player.points = 82 player.level_no = 1 player.save() update_points(player, None) coins = History.user_coins(player.user) self.assertIn('gold', coins) self.assertEqual(coins['gold'], 20) player.points = 10 player.save() update_points(player, None) coins = History.user_coins(player.user) self.assertIn('gold', coins) self.assertEqual(coins['gold'], 0)
def testUpdatePoints(self): IntegerListSetting.get('level_limits').set_value("80 125 180 245 320 450") Coin.add('points') Coin.add('gold') Formula.add('level-gold', expression='gold=10*{level}', owner=None) player = self._get_player() player.points = 82 player.level_no = 1 player.save() update_points(player, None) coins = History.user_coins(player.user) self.assertIn('gold', coins) self.assertEqual(coins['gold'], 20) player.points = 10 player.save() update_points(player, None) coins = History.user_coins(player.user) self.assertIn('gold', coins) self.assertEqual(coins['gold'], 0)
def testUpdatePoints(self): IntegerListSetting.get('level_limits').set_value( "80 125 180 245 320 450") Coin.add('points') Coin.add('gold') Formula.add('level-gold', expression='gold=10*{level}', owner=None) player = self._get_player() player.points = 82 player.level_no = 1 player.save() update_points(player, None) coins = History.user_coins(player.user) self.assertIn('gold', coins) self.assertEqual(coins['gold'], 20) player.points = 10 player.save() update_points(player, None) coins = History.user_coins(player.user) self.assertIn('gold', coins) self.assertEqual(coins['gold'], 0)
def testCalculate(self): formula = Formula.add('_test_formula', expression='_test=5', owner=self.game) # Call by name ret = scoring.calculate('_test_formula') self.assertTrue(isinstance(ret, dict)) # Call by object ret = scoring.calculate(formula) self.assertTrue(isinstance(ret, dict)) self.assertEqual(ret['_test'], 5) formula2 = Formula.add('_test_formula2', expression='_test=5*3', owner=self.game) ret = scoring.calculate(formula2) self.assertTrue(isinstance(ret, dict)) self.assertEqual(ret['_test'], 15) # Multiple coins formula2.expression = '_test=5*3; points=4' ret = scoring.calculate(formula2) self.assertTrue(isinstance(ret, dict)) self.assertEqual(ret['_test'], 15) self.assertEqual(ret['points'], 4) # Fail safe formula2.expression = '_test=5*cucu' try: ret = scoring.calculate(formula2) # no error? wtf self.assertFalse(True) except Exception as e: self.assertTrue(isinstance(e, FormulaParsingError))
def test_first_login_points(self): f = Formula.add('start-points', expression='points=10') Coin.add('points') player = self._get_player() self.assertEqual(player.points, 0) # this won't work, since the activity is sent in our custom view #self.client.login(username=player.user.username, password='******') # using this instead signals.addActivity.send(sender=None, user_from=player, action="login", game=None, public=False) player = Player.objects.get(pk=player.pk) self.assertEqual(player.points, 10)
def test_first_login_points(self): f = Formula.add('start-points', definition='points=10') Coin.add('points') player = self._get_player() self.assertEqual(player.points, 0) # this won't work, since the activity is sent in our custom view #self.client.login(username=player.user.username, password='******') # using this instead signals.addActivity.send(sender=None, user_from=player, action="login", game = None, public=False) player = Player.objects.get(pk=player.pk) self.assertEqual(player.points, 10)
def testScore(self): formula = Formula.add('_test_formula_sc', expression='_test=13', owner=self.game) scoring.score(self.user.get_profile(), self.game, formula, external_id=3) hs = scoring.history_for(self.user, self.game, external_id=3) self.assertTrue(isinstance(hs, QuerySet)) history = list(hs)[0] # check if specific coin has been updated self.assertEqual(history.coin, self.coin) self.assertEqual(history.amount, 13)
def testScore(self): formula = Formula.add('_test_formula_sc', definition='_test=13', owner=self.game) scoring.score(self.user.get_profile(), self.game, formula, external_id=3) hs = scoring.history_for(self.user, self.game, external_id=3) self.assertTrue(isinstance(hs, QuerySet)) history = list(hs)[0] # check if specific coin has been updated self.assertEqual(history.coin, self.coin) self.assertEqual(history.amount, 13)