Ejemplo n.º 1
0
 def setUp(self):
     self.user = User.objects.get(pk=1)
     self.context = Perspective()
Ejemplo n.º 2
0
class PerspectiveTestCase(TestCase):
    fixtures = ['test_data.yaml']

    def setUp(self):
        self.user = User.objects.get(pk=1)
        self.context = Perspective()

    def test_is_valid(self):
        self.assertTrue(self.context.is_valid({}))
        self.assertFalse(self.context.is_valid([]))

        class dict2(dict):
            pass

        self.assertTrue(self.context.is_valid(dict2()))

    def test_has_permission(self):
        self.assertTrue(self.context.has_permission())
        self.assertTrue(self.context.has_permission(user=self.user))

        node = {}

        self.assertTrue(self.context.has_permission(node))
        self.assertTrue(self.context.has_permission(node, self.user))

        node = {'columns': [1]}

        self.assertFalse(self.context.has_permission(node))
        self.assertFalse(self.context.has_permission(node, self.user))

        node = {'ordering': [(1, 'desc')]}

        self.assertFalse(self.context.has_permission(node))
        self.assertFalse(self.context.has_permission(node, self.user))