Example #1
0
class TestAllowSelfAuthorization(TestCase):
    fixtures = fixture('user_2519', 'user_999')

    def setUp(self):
        self.permission = AllowSelf()
        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.amo_user = self.request.user = self.user
        eq_(self.permission.has_permission(self.request, 'myview'), True)

    def test_has_object_permission_anonymous(self):
        eq_(self.permission.has_object_permission(
            self.request, 'myview', self.user), False)

    def test_has_object_permission_user(self):
        self.request.amo_user = self.request.user = self.user
        obj = 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 = self.user
        eq_(self.permission.has_object_permission(self.request, 'myview', obj),
            False)
class TestAllowSelfAuthorization(TestCase):
    fixtures = fixture("user_2519", "user_999")

    def setUp(self):
        self.permission = AllowSelf()
        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_anonymous(self):
        eq_(self.permission.has_object_permission(self.request, "myview", self.user), False)

    def test_has_object_permission_user(self):
        self.request.user = self.user
        self.request.amo_user = self.request.user.get_profile()
        obj = 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 = self.user
        eq_(self.permission.has_object_permission(self.request, "myview", obj), False)
Example #3
0
class TestAllowSelfAuthorization(TestCase):
    fixtures = fixture('user_2519', 'user_999')

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

    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
        eq_(self.permission.has_permission(self.request, 'myview'), True)

    def test_has_object_permission_anonymous(self):
        eq_(
            self.permission.has_object_permission(self.request, 'myview',
                                                  self.user), False)

    def test_has_object_permission_user(self):
        self.request.user = self.user
        obj = 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.user = self.request.user
        obj = self.user
        eq_(self.permission.has_object_permission(self.request, 'myview', obj),
            False)
Example #4
0
 def setUp(self):
     self.permission = AllowSelf()
     self.anonymous = AnonymousUser()
     self.user = User.objects.get(pk=2519)
     self.request = RequestFactory().get('/')
     self.request.user = self.anonymous
     self.request.amo_user = None
Example #5
0
 def setUp(self):
     self.permission = AllowSelf()
     self.anonymous = AnonymousUser()
     self.user = UserProfile.objects.get(pk=2519)
     self.request = RequestFactory().get('/')
     self.request.user = self.anonymous
     self.request.amo_user = None
Example #6
0
 def setUp(self):
     self.authorization = AllowSelf()
     self.anonymous = AnonymousUser()
     self.user = User.objects.get(pk=2519)
     self.request = RequestFactory().get('/')
     self.request.user = self.anonymous
     self.request.amo_user = None