'Call methods that emulate the adminsite instance\'s index.
This test was basically the reason for the new manager, in light of the
problem highlighted in ticket #1120, which asserts that giving a user
no site-specific rights when creating a GlobalPagePermission should
allow access to all sites.'

def test_emulate_admin_index(self):

    superuser = self._create_user('super', is_staff=True, is_active=True, is_superuser=True)
    superuser.set_password('super')
    superuser.save()
    site_1 = Site.objects.get(pk=1)
    site_2 = Site.objects.create(domain='example2.com', name='example2.com')
    SITES = [site_1, site_2]
    USERS = [self._create_user('staff', is_staff=True, is_active=True), self._create_user('staff_2', is_staff=True, is_active=True)]
    for user in USERS:
        user.set_password('staff')
        save_permissions({'can_add_page': True, 'can_change_page': True, 'can_delete_page': False}, user)
    GlobalPagePermission.objects.create(can_add=True, can_change=True, can_delete=False, user=USERS[0])
    self.assertEqual(1, GlobalPagePermission.objects.with_user(USERS[0]).count())
    GlobalPagePermission.objects.create(can_add=True, can_change=True, can_delete=False, user=USERS[1]).sites.add(SITES[0])
    self.assertEqual(1, GlobalPagePermission.objects.with_user(USERS[1]).count())
    homepage = create_page(title='master', template='nav_playground.html', language='en', in_navigation=True, slug='/')
    publish_page(page=homepage, user=superuser, language='en')
    with self.settings(CMS_PERMISSION=True):
        request = RequestFactory().get(path='/', data={'site__exact': site_1.pk})
        request.session = {}
        request.current_page = None
        for user in USERS:
            request.user = user
            with self.assertNumQueries(FuzzyInt(4, 5)):
                self.assertEqual({'add': True, 'change': True, 'delete': False}, site._registry[Page].get_model_perms(request))
        request = RequestFactory().get('/', data={'site__exact': site_2.pk})
        request.session = {}
        request.current_page = None
        USERS[0] = self.reload(USERS[0])
        USERS[1] = self.reload(USERS[1])
        with self.assertNumQueries(FuzzyInt(5, 15)):
            request.user = USERS[1]
            self.assertEqual({'add': False, 'change': False, 'delete': False}, site._registry[Page].get_model_perms(request))
            request = RequestFactory().get('/', data={'site__exact': site_2.pk})
            request.user = USERS[0]
            request.current_page = None
            self.assertEqual({'add': True, 'change': True, 'delete': False}, site._registry[Page].get_model_perms(request))
