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

    def setUp(self):
        self.permission = AllowOwner()
        self.anonymous = AnonymousUser()
        self.user = UserProfile.objects.get(pk=2519)
        self.request = RequestFactory().get('/')
        self.request.user = self.anonymous
        self.request.amo_user = None

    def test_has_permission_anonymous(self):
        eq_(self.permission.has_permission(self.request, 'myview'), False)

    def test_has_permission_user(self):
        self.request.user = self.user
        self.request.amo_user = self.request.user
        eq_(self.permission.has_permission(self.request, 'myview'), True)

    def test_has_object_permission_user(self):
        self.request.user = self.user
        self.request.amo_user = self.request.user
        obj = Mock()
        obj.user = self.user
        eq_(self.permission.has_object_permission(self.request, 'myview', obj),
            True)

    def test_has_object_permission_different_user(self):
        self.request.user = UserProfile.objects.get(pk=999)
        self.request.amo_user = self.request.user
        obj = Mock()
        obj.pk = self.user.pk
        eq_(self.permission.has_object_permission(self.request, 'myview', obj),
            False)
Exemplo n.º 2
0
class TestAllowOwner(TestCase):
    fixtures = fixture('user_2519', 'user_999')

    def setUp(self):
        self.authorization = AllowOwner()
        self.anonymous = AnonymousUser()
        self.user = User.objects.get(pk=2519)
        self.request = RequestFactory().get('/')
        self.request.user = self.anonymous
        self.request.amo_user = None

    def test_has_permission_anonymous(self):
        eq_(self.authorization.has_permission(self.request, 'myview'), False)

    def test_has_permission_user(self):
        self.request.user = self.user
        self.request.amo_user = self.request.user.get_profile()
        eq_(self.authorization.has_permission(self.request, 'myview'), True)

    def test_has_object_permission_user(self):
        self.request.user = self.user
        self.request.amo_user = self.request.user.get_profile()
        result = self.authorization.has_object_permission(self.request,
                                                          'myview', self)
        eq_(result, True)

    def test_has_object_permission_different_user(self):
        self.request.user = User.objects.get(pk=999)
        self.request.amo_user = self.request.user.get_profile()
        result = self.authorization.has_object_permission(self.request,
                                                          'myview', self)
        eq_(result, False)
Exemplo n.º 3
0
class TestAllowOwner(TestCase):
    fixtures = fixture("user_2519", "user_999")

    def setUp(self):
        self.permission = AllowOwner()
        self.anonymous = AnonymousUser()
        self.user = User.objects.get(pk=2519)
        self.request = RequestFactory().get("/")
        self.request.user = self.anonymous
        self.request.amo_user = None

    def test_has_permission_anonymous(self):
        eq_(self.permission.has_permission(self.request, "myview"), False)

    def test_has_permission_user(self):
        self.request.user = self.user
        self.request.amo_user = self.request.user.get_profile()
        eq_(self.permission.has_permission(self.request, "myview"), True)

    def test_has_object_permission_user(self):
        self.request.user = self.user
        self.request.amo_user = self.request.user.get_profile()
        obj = Mock()
        obj.user = self.user
        eq_(self.permission.has_object_permission(self.request, "myview", obj), True)

    def test_has_object_permission_different_user(self):
        self.request.user = User.objects.get(pk=999)
        self.request.amo_user = self.request.user.get_profile()
        obj = Mock()
        obj.user = self.user
        eq_(self.permission.has_object_permission(self.request, "myview", obj), False)
Exemplo n.º 4
0
 def setUp(self):
     self.permission = AllowOwner()
     self.anonymous = AnonymousUser()
     self.user = UserProfile.objects.get(pk=2519)
     self.request = RequestFactory().get('/')
     self.request.user = self.anonymous
     self.request.amo_user = None
Exemplo n.º 5
0
 def setUp(self):
     self.authorization = AllowOwner()
     self.anonymous = AnonymousUser()
     self.user = User.objects.get(pk=2519)
     self.request = RequestFactory().get('/')
     self.request.user = self.anonymous
     self.request.amo_user = None
Exemplo n.º 6
0
 def setUp(self):
     self.permission = AllowOwner()
     self.anonymous = AnonymousUser()
     self.user = UserProfile.objects.get(pk=2519)
     self.request = RequestFactory().get('/')
     self.request.user = self.anonymous