Exemplo n.º 1
0
class TestIsOperatorPermission(TestCase):
    fixtures = fixture('user_2519')

    def setUp(self):
        super(TestIsOperatorPermission, self).setUp()
        self.auth = IsOperatorPermission()
        self.user = UserProfile.objects.get(pk=2519)
        self.profile = self.user
        self.view = GenericAPIView()

    def is_authorized(self, anon=False):
        request = RequestFactory().get('/')
        request.user = AnonymousUser() if anon else self.user
        ACLMiddleware().process_request(request)
        return self.auth.has_permission(request, self.view)

    def test_anon(self):
        ok_(not self.is_authorized(anon=True))

    def test_auth_no_perm(self):
        ok_(not self.is_authorized())

    def test_auth_with_perm(self):
        OperatorPermission.objects.create(user=self.profile,
                                          region=1,
                                          carrier=8)
        ok_(self.is_authorized())
Exemplo n.º 2
0
class TestIsOperatorPermission(TestCase):
    fixtures = fixture('user_2519')

    def setUp(self):
        super(TestIsOperatorPermission, self).setUp()
        self.auth = IsOperatorPermission()
        self.user = UserProfile.objects.get(pk=2519)
        self.profile = self.user
        self.view = GenericAPIView()

    def is_authorized(self, anon=False):
        request = RequestFactory().get('/')
        request.user = AnonymousUser() if anon else self.user
        ACLMiddleware().process_request(request)
        return self.auth.has_permission(request, self.view)

    def test_anon(self):
        ok_(not self.is_authorized(anon=True))

    def test_auth_no_perm(self):
        ok_(not self.is_authorized())

    def test_auth_with_perm(self):
        OperatorPermission.objects.create(user=self.profile, region=1,
                                          carrier=8)
        ok_(self.is_authorized())
Exemplo n.º 3
0
 def setUp(self):
     super(TestIsOperatorPermission, self).setUp()
     self.auth = IsOperatorPermission()
     self.user = UserProfile.objects.get(pk=2519)
     self.profile = self.user
     self.view = GenericAPIView()
Exemplo n.º 4
0
 def setUp(self):
     super(TestIsOperatorPermission, self).setUp()
     self.auth = IsOperatorPermission()
     self.user = UserProfile.objects.get(pk=2519)
     self.profile = self.user
     self.view = GenericAPIView()