def test_request_permission(self):
        self.client.login(username="test2", password="password")

        # get should be disallowed
        response = self.client.get(reverse("test_request_perm"))
        perm_url = reverse(
            "permissions_url",
            kwargs=dict(
                perm_name="test_request_perm",
                permittee_ct_id=ContentType.objects.get_for_model(User).id,
                permittee_id = self.u2.id,
                target_ct_id=ContentType.objects.get_for_model(ContentType).id,
                target_id=ContentType.objects.get_for_model(PermissionTestClass).id,
            )
        )
        self.assertRedirects(response, perm_url)
        self.assertEqual(
            self.client.session['from_url'], reverse("test_request_perm"))
        
        # post a request for the permission
        self.assertEqual(PermissionRequest.objects.count(), 0)
        response = self.client.post(perm_url, {"permission_owner": self.u1.id,
                                               "message": "hello",})
        self.assertRedirects(response, reverse("test_allowed"))
        self.assertEqual(PermissionRequest.objects.count(), 1)
        perm_req = PermissionRequest.objects.all()[0]
        self.assertEqual(perm_req.requesting_user, self.u2)
        self.assertEqual(
            perm_req.permittee,
            Permittee.objects.get_as_permittee(self.u2))
        self.assertEqual(perm_req.permission_owner, self.u1)
        self.assertEqual(
            perm_req.requested_permission.target,
            ContentType.objects.get_for_model(PermissionTestClass))
        self.assertEqual(perm_req.requested_permission.permission.name,
                         "test_request_perm")
        self.assertEqual(perm_req.message, "hello")
        
        perm_req.allow()

        # get should be allowed now
        response = self.client.get(reverse("test_request_perm"))
        self.assertEqual(response.status_code, 200)
Test the generic request_permission view for permissions.
dataset/ETHPy150Open fp7-ofelia/ocf/expedient/src/python/expedient/common/permissions/tests/tests.py/TestRequests.test_request_permission