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!")
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)
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))
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())
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)
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]))
def test_new(self): target = DiceRoll('test description') self.assertIsNotNone(target.GUID) self.assertEqual('test description', target.description) self.assertEqual(0, len(target.rolls))
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}))