示例#1
0
    def test_post_fail(self, randint, redis):
        randint.return_value = 7
        roll = DiceRoll('description test')
        roll.roll(1)
        DiceRollManager.get_manager().redis.get.return_value = pickle.dumps(roll)

        response = self.app.get(reverse('diceroll', kwargs={'id': roll.GUID}))
        self.assertContains(response, "FAIL!")
示例#2
0
    def test_roll_explode(self, random_call):
        results = [1, 10, 10, 8, 10, 9]
        random_call.side_effect = results

        target = DiceRoll('test description')
        target.roll(3)

        self.assertEqual(1, len(target.rolls))
        self.assertEqual(results, target.rolls[0].values)
示例#3
0
    def test_roll_explode(self, random_call):
        results = [1, 10, 10, 8, 10, 9]
        random_call.side_effect = results

        target = DiceRoll('test description')
        target.roll(3)

        self.assertEqual(1, len(target.rolls))
        self.assertEqual(results, target.rolls[0].values)
示例#4
0
    def test_multiple_rolls(self, random_call):
        random_call.side_effect = [1, 1, 1, 1, 1]
        target = DiceRoll('test description')

        target.roll(2)
        target.roll(3)

        self.assertEqual(2, len(target.rolls))
        self.assertEqual(3, len(target.rolls[0].values))
        self.assertEqual(2, len(target.rolls[1].values))
示例#5
0
    def test_roll(self, random_call):
        results = [1, 4, 7, 8, 6, 9]
        random_call.side_effect = results

        target = DiceRoll('test description')
        target.roll(6)

        self.assertEqual(1, len(target.rolls))
        self.assertEqual(results, target.rolls[0].values)
        self.assertEqual(2, target.rolls[0].successes())
示例#6
0
    def test_multiple_rolls(self, random_call):
        random_call.side_effect = [1, 1, 1, 1, 1]
        target = DiceRoll('test description')

        target.roll(2)
        target.roll(3)

        self.assertEqual(2, len(target.rolls))
        self.assertEqual(3, len(target.rolls[0].values))
        self.assertEqual(2, len(target.rolls[1].values))
示例#7
0
    def test_roll(self, random_call):
        results = [1, 4, 7, 8, 6, 9]
        random_call.side_effect = results

        target = DiceRoll('test description')
        target.roll(6)

        self.assertEqual(1, len(target.rolls))
        self.assertEqual(results, target.rolls[0].values)
        self.assertEqual(2, target.rolls[0].successes())
示例#8
0
    def test_display_new_diceroll_form_on_home(self, redis):
        roll1 = DiceRoll('desc1')
        roll2 = DiceRoll('desc2')
        roll3 = DiceRoll('desc3')


        DiceRollManager.get_manager().redis.scan_iter.return_value = \
            [roll1.GUID, roll2.GUID, roll3.GUID]
        DiceRollManager.get_manager().redis.get.side_effect = [
            pickle.dumps(x) for x in [roll1, roll2, roll3]
        ]
        response = self.app.get(reverse('home'))
        self.assertIsNotNone(response.form)

        self.assertContains(response, reverse('diceroll', kwargs={'id': roll1.GUID}))
        self.assertContains(response, roll1.description)
        self.assertContains(response, reverse('diceroll', kwargs={'id': roll2.GUID}))
        self.assertContains(response, roll2.description)
        self.assertContains(response, reverse('diceroll', kwargs={'id': roll3.GUID}))
        self.assertContains(response, roll3.description)
示例#9
0
    def test_post_roll(self, redis):
        roll = DiceRoll('description test')
        DiceRollManager.get_manager().redis.get.return_value = pickle.dumps(roll)
        result = {}
        def stub_set(guid, pickled_obj):
            result['guid'] = guid
            result['pickled_obj'] = pickled_obj
        DiceRollManager.get_manager().redis.set.side_effect = stub_set

        response = self.app.get(reverse('diceroll', kwargs={'id': roll.GUID}))
        self.assertIsNotNone(response.form)
        response.form['dicenum'] = 10
        response = response.form.submit()

        DiceRollManager.get_manager().redis.set.assert_called_with(roll.GUID,
                                                                   result['pickled_obj'])
        DiceRollManager.get_manager().redis.get.return_value = result['pickled_obj']

        response = response.follow()

        roll = pickle.loads(result['pickled_obj'])
        self.assertEqual(1, len(roll.rolls))
        self.assertContains(response, ', '.join([unicode(v) for v in roll.rolls[0].values]))
示例#10
0
 def test_new(self):
     target = DiceRoll('test description')
     self.assertIsNotNone(target.GUID)
     self.assertEqual('test description', target.description)
     self.assertEqual(0, len(target.rolls))
示例#11
0
 def test_get_view(self, redis):
     roll = DiceRoll('description test')
     DiceRollManager.get_manager().redis.get.return_value = pickle.dumps(roll)
     response = self.app.get(reverse('diceroll', kwargs={'id': roll.GUID}))
     DiceRollManager.get_manager().redis.get.assert_called_with(roll.GUID)
     self.assertContains(response, reverse('diceroll', kwargs={'id': roll.GUID}))