def setUp(self):
     self.act_with_perm = ActionWithPermission("test-action")
class TestActionWithPermission(DebugPrintingTestCase):
    def setUp(self):
        self.act_with_perm = ActionWithPermission("test-action")

    @skip
    def test_add_permit(self):
        self.act_with_perm.add_permit("allow", 20)
        self.act_with_perm.add_permit("deny", 30)
        self.act_with_perm.add_permit("allow", 40)
        self.assertItemsEqual(self.act_with_perm.weighted_permits, set([("allow", 20), ("deny", 30), ("allow", 40)]))

    @skip
    def test_add_duplicate_permit(self):
        self.act_with_perm.add_permit("allow", 20)
        self.act_with_perm.add_permit("deny", 30)
        self.act_with_perm.add_permit("allow", 20)
        self.assertItemsEqual(self.act_with_perm.weighted_permits, set([("allow", 20), ("deny", 30)]))

    @skip
    def test_add_conflicting_permit(self):
        with self.assertRaises(CompetitionDataError):
            self.act_with_perm.add_permit("allow", 20)
            self.act_with_perm.add_permit("deny", 30)
            self.act_with_perm.add_permit("deny", 20)

    def test_sorted_permits(self):
        self.act_with_perm.add_permit("allow", 70)
        self.act_with_perm.add_permit("deny", 80)
        self.act_with_perm.add_permit("allow", 90)
        self.assertEqual(self.act_with_perm._sorted_permits(), [("allow", 90), ("deny", 80), ("allow", 70)])

    def test_allowed(self):
        self.act_with_perm.add_permit("allow", 70)
        self.act_with_perm.add_permit("deny", 80)
        self.assertFalse(self.act_with_perm.allowed)
        self.act_with_perm.add_permit("allow", 90)
        self.assertTrue(self.act_with_perm.allowed)

    def test_representation(self):
        self.act_with_perm.add_permit("allow", 70)
        self.act_with_perm.add_permit("deny", 80)
        self.assertEqual(
            self.act_with_perm.__repr__(),
            '<ActionWithPermission "test-action", ' + "perms=[('deny', 80), ('allow', 70)]>",
        )