'User can edit page view restrictions if he has
change permissions on the Page model,
change permissions on the PagePermission model,
global change permission and global change permissions permission.'

def test_user_can_edit_page_view_restrictions(self):

    admin = self.get_superuser()
    page = self.get_permissions_test_page()
    endpoint = (self.get_admin_url(Page, 'permissions', page.pk) + '?language=en')
    staff_user = self.get_staff_user_with_no_permissions()
    staff_user_2 = self.get_staff_page_user(created_by=admin)
    permission = self.add_page_permission(user=staff_user_2, page=page, can_view=True, grant_on=1)
    data = model_to_dict(permission, exclude=['group'])
    data['grant_on'] = 5
    data = self._get_page_view_restrictions_data(**data)
    data['_continue'] = '1'
    self.add_permission(staff_user, 'change_page')
    self.add_permission(staff_user, 'change_pagepermission')
    self.add_global_permission(staff_user, can_change=True, can_change_permissions=True)
    with self.login_user_context(staff_user):
        response = self.client.post(endpoint, data)
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, endpoint)
        self.assertTrue(self._page_permission_exists(user=staff_user_2, grant_on=5))
