Beispiel #1
0
    def setUp(self):
        super(TestUserPageVisitView, self).setUp()

        self.user = UserFactory()
        self.page = PageFactory(path="002", numchild=1)
        self.other_page = PageFactory(path="002001", numchild=0)
        self.path = reverse('api:v1:userpagevisit-list')
        self.client.login(username=self.user.username, password='******')
    def setUpClass(cls):
        super(TestSearchAPI, cls).setUpClass()

        cls.test_about_page_slug = 'journal-about-page-slug'

        cls.user = UserFactory()
        cls.site = Site.objects.first()
        cls.org = OrganizationFactory(site=cls.site)
        cls.journal = JournalFactory(organization=cls.org)
        cls.journal_access = JournalAccessFactory(
            journal=cls.journal,
            user=cls.user,
            expiration_date=datetime.date.today() + datetime.timedelta(days=1))
        cls.journal_about_page = create_journal_about_page_factory(
            journal=cls.journal,
            journal_structure=cls.get_journal_test_data(),
            root_page=cls.site.root_page,
            about_page_slug=cls.test_about_page_slug,
        )

        cls._update_index()

        cls.multi_journal_search_path = reverse('api:v1:multi_journal_search')
        cls.single_journal_search_path = reverse('api:v1:journal_search',
                                                 args=(cls.journal.id, ))
        cls.common_query_string = 'title'
    def setUp(self):
        super(TestSiteBrandingAPI, self).setUp()

        self.user = UserFactory()

        self.path = "/api/v1/sitebranding/"
        self.client.login(username=self.user.username, password=USER_PASSWORD)
Beispiel #4
0
    def test_is_staff_permission(self):
        """
        Test the UserPageVisitView's permissions
        """
        # non-staff user can get its own visits
        self._create_user_page_visit(self.user, self.page)
        response = self.client.get(self.path)
        self._assert_user_page_visit(response, self.user, self.page)

        # non-staff user can not get any other user's visits
        other_user = UserFactory()
        self._create_user_page_visit(other_user, self.page)
        path_with_parameters = "{path}?page_id={page_id}&user_id={user_id}".format(
            path=self.path,
            page_id=self.page.id,
            user_id=other_user.id,
        )
        response = self.client.get(path_with_parameters)
        self.assertEqual(response.status_code, 200)
        response_data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(response_data), 0)

        # staff user can get any user's visits.
        self.user.is_staff = True
        self.user.save()
        response = self.client.get(path_with_parameters)
        self._assert_user_page_visit(response, other_user, self.page)
 def test_notification_settings_disabled_on_user_creation(self):
     """
     Test user's notifications preferences are disabled at the time of user creation
     """
     user = UserFactory()
     self.assertFalse(user.wagtail_userprofile.submitted_notifications)
     self.assertFalse(user.wagtail_userprofile.approved_notifications)
     self.assertFalse(user.wagtail_userprofile.rejected_notifications)
Beispiel #6
0
    def setUp(self):
        super(TestUserRequireAuthView, self).setUp()

        self.user = UserFactory()
        self.site = Site.objects.first()
        self.site_configuration = SiteConfigurationFactory(site=self.site)
        self.client.login(username=self.user.username, password='******')
        self.path = reverse("require_auth")
 def setUp(self):
     super(TestJournalPage, self).setUp()
     self.user = UserFactory()
     self.user.is_superuser = True
     self.user.save()
     self.site = Site.objects.first()
     self.site_configuration = SiteConfigurationFactory(site=self.site)
     self.org = OrganizationFactory(site=self.site)
     self.journal = JournalFactory(
         organization=self.org
     )
     self.journal_about_page = create_journal_about_page_factory(
         journal=self.journal,
         journal_structure=self.journal_test_data,
         root_page=self.site.root_page,
         about_page_slug='journal-about-page-slug'
     )
     self.path = reverse('wagtailadmin_explore_root')
     self.client.login(username=self.user.username, password=USER_PASSWORD)
 def test_notification_settings_can_be_enbled(self):
     """
     Test user's notifications preferences can be enabled by updating user's profile
     """
     user = UserFactory()
     userprofile = user.wagtail_userprofile
     userprofile.submitted_notifications = True
     userprofile.approved_notifications = True
     userprofile.rejected_notifications = True
     userprofile.save()
     self.assertTrue(user.wagtail_userprofile.submitted_notifications)
     self.assertTrue(user.wagtail_userprofile.approved_notifications)
     self.assertTrue(user.wagtail_userprofile.rejected_notifications)
Beispiel #9
0
    def setUp(self):
        super(TestContentPagesAPI, self).setUp()

        self.user = UserFactory()
        self.test_about_page_slug = 'journal-about-page-slug'
        self.site = Site.objects.first()
        self.org = OrganizationFactory(site=self.site)
        self.journal = JournalFactory(organization=self.org)
        self.journal_access = JournalAccessFactory(
            journal=self.journal,
            user=self.user,
            expiration_date=datetime.date.today() + datetime.timedelta(days=1))
        self.journal_about_page = create_journal_about_page_factory(
            journal=self.journal,
            journal_structure=self.journal_test_data,
            root_page=self.site.root_page,
            about_page_slug=self.test_about_page_slug,
        )
        self.path = reverse('content:pages:listing')
        self.client.login(username=self.user.username, password=USER_PASSWORD)
class TestJournalPage(TestCase):
    """
    Test Cases for Journal Page.
    """

    def setUp(self):
        super(TestJournalPage, self).setUp()
        self.user = UserFactory()
        self.user.is_superuser = True
        self.user.save()
        self.site = Site.objects.first()
        self.site_configuration = SiteConfigurationFactory(site=self.site)
        self.org = OrganizationFactory(site=self.site)
        self.journal = JournalFactory(
            organization=self.org
        )
        self.journal_about_page = create_journal_about_page_factory(
            journal=self.journal,
            journal_structure=self.journal_test_data,
            root_page=self.site.root_page,
            about_page_slug='journal-about-page-slug'
        )
        self.path = reverse('wagtailadmin_explore_root')
        self.client.login(username=self.user.username, password=USER_PASSWORD)

    @property
    def journal_test_data(self):
        """
        Returns the test data\
        """
        return {
            "title": "test_journal_about_page",
            "structure": [
                {
                    "title": "test_page_1",
                    "children": [
                        {
                            "title": "test_page_1_child_1",
                            "children": [
                                {
                                    "title": "test_page_1_grand_child_1",
                                    "children": [
                                        {
                                            "title": "test_page_1_grand_child_1_grand_child_1",
                                            "children": [
                                                {
                                                    "title": "test_page_1_grand_child_1_grand_child_1_grand_child_1",
                                                    "children": []
                                                },
                                            ]
                                        },
                                        {
                                            "title": "test_page_1_grand_child_1_grand_child_2",
                                            "children": []
                                        }
                                    ]
                                },
                                {
                                    "title": "test_page_1_grand_child_2",
                                    "children": []
                                }
                            ]
                        }
                    ]
                },
            ]
        }

    @classmethod
    def setUpClass(cls):
        super(TestJournalPage, cls).setUpClass()
        disconnect_page_signals_handlers()

    @classmethod
    def tearDownClass(cls):
        connect_page_signals_handlers()
        super(TestJournalPage, cls).tearDownClass()

    def _get_previous_page(self, page):
        """
        Returns the previous page of journals page
        """
        return JournalPage.objects.get(title=page.title).get_prev_page()

    def _get_next_page(self, page):
        """
        Returns the next page of journals page
        """
        return JournalPage.objects.get(title=page.title).get_next_page()

    def test_pub_unpub_pub_pattern(self):
        """
        Test the 'pub->unpub->pub' pattern
        """
        response = self.client.get(self.path)
        self.assertEqual(response.status_code, 200)

        self.journal_about_page.save_revision().publish()
        self.journal_about_page.get_children()[0].unpublish()
        self.journal_about_page.get_children()[0].get_children()[0].save_revision().publish()

        journal_pages = self.journal_about_page.get_children()
        self.assertEqual(
            self._get_next_page(journal_pages[0]).title,
            "test_page_1_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_pages[0]))  # because its journal_about_page

        journal_child_pages = journal_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_child_pages[0]).title,
            "test_page_1_grand_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_child_pages[0]))  # because its unpublished

        journal_grand_child_pages = journal_child_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_grand_child_pages[0]).title,
            "test_page_1_grand_child_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_grand_child_pages[0]).title,
            "test_page_1_child_1"
        )

    def test_unpub_unpub_pub_pattern(self):
        """
        Test the 'unpub->unpub->pub' pattern
        """
        response = self.client.get(self.path)
        self.assertEqual(response.status_code, 200)
        self.journal_about_page.unpublish()
        self.journal_about_page.get_children()[0].unpublish()
        self.journal_about_page.get_children()[0].get_children()[0].save_revision().publish()

        journal_pages = self.journal_about_page.get_children()
        self.assertEqual(
            self._get_next_page(journal_pages[0]).title,
            "test_page_1_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_pages[0]))  # because its journal_about_page

        journal_child_pages = journal_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_child_pages[0]).title,
            "test_page_1_grand_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_child_pages[0]))  # because its unpublished

        journal_grand_child_pages = journal_child_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_grand_child_pages[0]).title,
            "test_page_1_grand_child_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_grand_child_pages[0]).title,
            "test_page_1_child_1"
        )

    def test_unpub_pub_pub_pattern(self):
        """
        Test the 'unpup->pub->pub' pattern
        """
        response = self.client.get(self.path)
        self.assertEqual(response.status_code, 200)
        self.journal_about_page.unpublish()
        self.journal_about_page.get_children()[0].save_revision().publish()
        self.journal_about_page.get_children()[0].get_children()[0].save_revision().publish()

        journal_pages = self.journal_about_page.get_children()
        self.assertEqual(
            self._get_next_page(journal_pages[0]).title,
            "test_page_1_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_pages[0]))  # because its journal_about_page

        journal_child_pages = journal_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_child_pages[0]).title,
            "test_page_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_child_pages[0]).title,
            "test_page_1"
        )

        journal_grand_child_pages = journal_child_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_grand_child_pages[0]).title,
            "test_page_1_grand_child_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_grand_child_pages[0]).title,
            "test_page_1_child_1"
        )

    def test_pub_unpub_unpub_pub_pattern(self):
        """
        Test the 'pub->unpub->unpub->pub' pattern
        """
        response = self.client.get(self.path)
        self.assertEqual(response.status_code, 200)
        self.journal_about_page.save_revision().publish()
        self.journal_about_page.get_children()[0].unpublish()
        self.journal_about_page.get_children()[0].get_children()[0].unpublish()
        self.journal_about_page.get_children()[0].get_children()[0].get_children()[0].save_revision().publish()

        journal_pages = self.journal_about_page.get_children()
        self.assertEqual(
            self._get_next_page(journal_pages[0]).title,
            "test_page_1_grand_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_pages[0]))  # because its journal_about_page

        journal_child_pages = journal_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_child_pages[0]).title,
            "test_page_1_grand_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_child_pages[0]))

        journal_grand_child_pages = journal_child_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_grand_child_pages[0]).title,
            "test_page_1_grand_child_1_grand_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_grand_child_pages[0]))

        journal_grand_grand_child_pages = journal_grand_child_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_grand_grand_child_pages[0]).title,
            "test_page_1_grand_child_1_grand_child_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_grand_grand_child_pages[0]).title,
            "test_page_1_grand_child_1"
        )

    def test_unpub_pub_unpub_pub_pattern(self):
        """
        Test the 'unpub->pub->unpub->pub' pattern
        """
        response = self.client.get(self.path)
        self.assertEqual(response.status_code, 200)
        self.journal_about_page.unpublish()
        self.journal_about_page.get_children()[0].save_revision().publish()
        self.journal_about_page.get_children()[0].get_children()[0].unpublish()
        self.journal_about_page.get_children()[0].get_children()[0].get_children()[0].save_revision().publish()

        journal_pages = self.journal_about_page.get_children()
        self.assertEqual(
            self._get_next_page(journal_pages[0]).title,
            "test_page_1_grand_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_pages[0]))  # because its journal_about_page

        journal_child_pages = journal_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_child_pages[0]).title,
            "test_page_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_child_pages[0]).title,
            "test_page_1"
        )

        journal_grand_child_pages = journal_child_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_grand_child_pages[0]).title,
            "test_page_1_grand_child_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_grand_child_pages[0]).title,
            "test_page_1"
        )

        journal_grand_grand_child_pages = journal_grand_child_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_grand_grand_child_pages[0]).title,
            "test_page_1_grand_child_1_grand_child_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_grand_grand_child_pages[0]).title,
            "test_page_1_grand_child_1"
        )

    def test_unpub_pattern(self):
        """
        Test the 'unpub' pattern
        """
        response = self.client.get(self.path)
        self.assertEqual(response.status_code, 200)
        self.journal_about_page.unpublish()

        journal_pages = self.journal_about_page.get_children()
        self.assertEqual(
            self._get_next_page(journal_pages[0]).title,
            "test_page_1_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_pages[0]))  # because its journal_about_page

        journal_child_pages = journal_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_child_pages[0]).title,
            "test_page_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_child_pages[0]).title,
            "test_page_1"
        )

    def test_pub_unpub_pattern(self):
        """
        Test the 'pub->unpub' pattern
        """
        response = self.client.get(self.path)
        self.assertEqual(response.status_code, 200)
        self.journal_about_page.unpublish()

        journal_pages = self.journal_about_page.get_children()
        self.assertEqual(
            self._get_next_page(journal_pages[0]).title,
            "test_page_1_child_1"
        )
        self.assertIsNone(self._get_previous_page(journal_pages[0]))  # because its journal_about_page

        journal_child_pages = journal_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_child_pages[0]).title,
            "test_page_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_child_pages[0]).title,
            "test_page_1"
        )

        journal_grand_child_pages = journal_child_pages[0].get_children()
        self.assertEqual(
            self._get_next_page(journal_grand_child_pages[0]).title,
            "test_page_1_grand_child_1_grand_child_1"
        )
        self.assertEqual(
            self._get_previous_page(journal_grand_child_pages[0]).title,
            "test_page_1_child_1"
        )
Beispiel #11
0
class TestJournalAboutPageStructure(TestCase):
    """ Test Cases for journal about page structure """
    @classmethod
    def setUpClass(cls):
        super(TestJournalAboutPageStructure, cls).setUpClass()
        disconnect_page_signals_handlers()

    @classmethod
    def tearDownClass(cls):
        connect_page_signals_handlers()
        super(TestJournalAboutPageStructure, cls).tearDownClass()

    def setUp(self):
        super(TestJournalAboutPageStructure, self).setUp()

        self.user = UserFactory()
        self.user.is_superuser = True
        self.user.save()
        self.test_about_page_slug = 'journal-about-page-slug'
        self.site = Site.objects.first()
        self.site_configuration = SiteConfigurationFactory(site=self.site)
        self.org = OrganizationFactory(site=self.site)
        self.journal = JournalFactory(organization=self.org)
        self.journal_about_page = create_journal_about_page_factory(
            journal=self.journal,
            journal_structure=self.journal_test_data,
            root_page=self.site.root_page,
            about_page_slug=self.test_about_page_slug)

        self.path = reverse('wagtailadmin_explore_root')
        self.client.login(username=self.user.username, password=USER_PASSWORD)

    @property
    def journal_test_data(self):
        return {
            "title":
            "test_journal_about_page",
            "structure": [{
                "title":
                "test_page_1",
                "children": [{
                    "title":
                    "test_page_1_child_1",
                    "children": [{
                        "title": "test_page_1_grand_child_1",
                        "children": []
                    }, {
                        "title": "test_page_1_grand_child_2",
                        "children": []
                    }]
                }, {
                    "title": "test_page_1_child_2",
                    "children": []
                }]
            }, {
                "title": "test_page_2",
                "children": []
            }, {
                "title":
                "test_page_3",
                "children": [{
                    "title": "test_page_3_child_1",
                    "children": []
                }, {
                    "title": "test_page_3_child_2",
                    "children": []
                }]
            }]
        }

    def _assert_page_hierarchy(self):
        """
        asserts pages under journal about page are in correct hierarchy
        """
        # assert journal about page has right child count
        self.assertEqual(self.journal_about_page.get_descendant_count(), 9)
        self.assertEqual(self.journal_about_page.get_children_count(), 3)
        journal_pages = self.journal_about_page.get_children()
        for index, page in enumerate(journal_pages):
            self.assertEqual(page.title,
                             "_".join(["test_page",
                                       str(index + 1)]))

        # assert journal pages has right child count
        journal_page_1 = journal_pages[0]
        self.assertEqual(journal_page_1.get_children_count(), 2)
        journal_page_1_children = journal_page_1.get_children()
        for index, page in enumerate(journal_page_1_children):
            self.assertEqual(page.title,
                             "_".join(["test_page_1_child",
                                       str(index + 1)]))

        journal_page_2 = journal_pages[1]
        self.assertEqual(journal_page_2.get_children_count(), 0)

        journal_page_3 = journal_pages[2]
        self.assertEqual(journal_page_3.get_children_count(), 2)
        journal_page_3_children = journal_page_3.get_children()
        for index, page in enumerate(journal_page_3_children):
            self.assertEqual(page.title,
                             "_".join(["test_page_3_child",
                                       str(index + 1)]))

        # assert journal page has right grand child count
        journal_page_1_child_1_children = journal_page_1_children[
            0].get_children()
        self.assertEqual(len(journal_page_1_child_1_children), 2)
        for index, page in enumerate(journal_page_1_child_1_children):
            self.assertEqual(
                page.title,
                "_".join(["test_page_1_grand_child",
                          str(index + 1)]))

        self.assertEqual(journal_page_1_children[1].get_children_count(), 0)

    def test_get_pages(self):
        """
        Tests journal about page structure under different publish/unpublish scenarios
        """
        response = self.client.get(self.path)
        self.assertEqual(response.status_code, 200)

        self.journal_about_page.save_revision().publish()
        self.journal_about_page.get_children()[0].unpublish()
        self.journal_about_page.get_children()[0].get_children(
        )[0].save_revision().publish()
        self._assert_page_hierarchy()

        self.journal_about_page.unpublish()
        self.journal_about_page.get_children()[2].unpublish()
        self.journal_about_page.get_children()[2].get_children(
        )[1].save_revision().publish()
        self._assert_page_hierarchy()

        self.journal_about_page.unpublish()
        self.journal_about_page.get_children()[2].save_revision().publish()
        self.journal_about_page.get_children()[2].get_children(
        )[1].save_revision().publish()
        self._assert_page_hierarchy()

        self.journal_about_page.save_revision().publish()
        self.journal_about_page.get_children()[0].unpublish()
        self.journal_about_page.get_children()[0].get_children()[0].unpublish()
        self.journal_about_page.get_children()[0].get_children(
        )[0].get_children()[0].save_revision().publish()
        self._assert_page_hierarchy()

        self.journal_about_page.unpublish()
        self.journal_about_page.get_children()[0].save_revision().publish()
        self.journal_about_page.get_children()[0].get_children()[0].unpublish()
        self.journal_about_page.get_children()[0].get_children(
        )[0].get_children()[0].save_revision().publish()
        self._assert_page_hierarchy()
Beispiel #12
0
class TestUserPageVisitView(TestCase):
    """
    Test Cases for UserPageVisitView
    """
    def setUp(self):
        super(TestUserPageVisitView, self).setUp()

        self.user = UserFactory()
        self.page = PageFactory(path="002", numchild=1)
        self.other_page = PageFactory(path="002001", numchild=0)
        self.path = reverse('api:v1:userpagevisit-list')
        self.client.login(username=self.user.username, password='******')

    def _create_user_page_visit(self, user, page):
        """
        Created the UserPageVisit's object with the given user and page objects. We temporarily change user to staff
        because POSTs are protected and only staff can create posts for other users.
        """
        staff_state = self.user.is_staff
        self.user.is_staff = True
        self.user.save()

        self.client.post(self.path, {
            "user": user.id,
            "page": page.id,
        })

        self.user.is_staff = staff_state
        self.user.save()

    def _assert_user_page_visit(self, response, user, page):
        """
        Assert the given response with the given user and page object.
        """
        response_data = json.loads(response.content.decode('utf-8'))

        self.assertEqual(len(response_data), 1)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response_data[0]['page'], page.id)
        self.assertEqual(response_data[0]['user'], user.id)

    def test_get_request(self):
        """
        Test the get functionality of UserPageVisitView
        """
        # this should return zero objects because
        # we didn't create any UserPageVisit object
        response = self.client.get(self.path)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(json.loads(response.content.decode('utf-8'))), 0)

        self._create_user_page_visit(self.user, self.page)
        response = self.client.get(self.path)
        self._assert_user_page_visit(response, self.user, self.page)

    def test_create_request(self):
        """
        Test the create functionality of UserPageVisitView
        """
        self._create_user_page_visit(self.user, self.page)
        self._create_user_page_visit(self.user, self.other_page)
        response = self.client.get(self.path)
        response_data = json.loads(response.content.decode('utf-8'))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response_data), 2)

    def test_search_on_page(self):
        """
        Test the UserPageVisitView, by searching on the base of page id.
        """
        self._create_user_page_visit(self.user, self.page)
        self._create_user_page_visit(self.user, self.other_page)
        path_with_parameters = "{path}?page_id={page_id}".format(
            path=self.path, page_id=self.other_page.id)
        response = self.client.get(path_with_parameters)
        self._assert_user_page_visit(response, self.user, self.other_page)

    def test_get_last_page(self):
        """
        Test the UserPageVisitView, by getting the last page visit of a user.
        """
        self._create_user_page_visit(self.user, self.other_page)
        self._create_user_page_visit(self.user, self.page)
        path_with_parameters = "{path}?last_visit=true".format(
            path=self.path, )
        response = self.client.get(path_with_parameters)

        # API should return the UserPageVisit object which was created later.
        self._assert_user_page_visit(response, self.user, self.page)

    def test_login_permission(self):
        """
        Test the UserPageVisitView's permissions
        """
        self._create_user_page_visit(self.user, self.page)
        response = self.client.get(self.path)
        self._assert_user_page_visit(response, self.user, self.page)

        self.client.logout()
        response = self.client.get(self.path)
        self.assertEqual(response.status_code, 403)

    def test_is_staff_permission(self):
        """
        Test the UserPageVisitView's permissions
        """
        # non-staff user can get its own visits
        self._create_user_page_visit(self.user, self.page)
        response = self.client.get(self.path)
        self._assert_user_page_visit(response, self.user, self.page)

        # non-staff user can not get any other user's visits
        other_user = UserFactory()
        self._create_user_page_visit(other_user, self.page)
        path_with_parameters = "{path}?page_id={page_id}&user_id={user_id}".format(
            path=self.path,
            page_id=self.page.id,
            user_id=other_user.id,
        )
        response = self.client.get(path_with_parameters)
        self.assertEqual(response.status_code, 200)
        response_data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(response_data), 0)

        # staff user can get any user's visits.
        self.user.is_staff = True
        self.user.save()
        response = self.client.get(path_with_parameters)
        self._assert_user_page_visit(response, other_user, self.page)