def test_template_filter(self): template_1 = get_cms_setting('TEMPLATES')[0][0] template_2 = get_cms_setting('TEMPLATES')[1][0] template_1_pages = PageContentWithVersionFactory.create_batch( 3, template=template_1, language="en") template_2_pages = PageContentWithVersionFactory.create_batch( 3, template=template_2, language="en") base_url = self.get_admin_url(PageContent, "changelist") with self.login_user_context(self.get_superuser()): # All / No templates filtered is the default response_default = self.client.get(base_url) # fullwidth template set response_template_1 = self.client.get( base_url + "?template={}".format(template_1)) # page template set response_template_2 = self.client.get( base_url + "?template={}".format(template_2)) self.assertSetEqual(set(response_default.context["cl"].queryset), set(template_1_pages) | set(template_2_pages)) self.assertSetEqual(set(response_template_1.context["cl"].queryset), set(template_1_pages)) self.assertSetEqual(set(response_template_2.context["cl"].queryset), set(template_2_pages))
def test_unpublished_filter(self): expected = PageContentWithVersionFactory.create_batch(3, language="en") expected_unpublished = PageContentWithVersionFactory.create_batch( 2, language="en", version__state=UNPUBLISHED) model = PageContent base_url = self.get_admin_url(model, "changelist") with self.login_user_context(self.get_superuser()): # en is the default language configured for the site response_default = self.client.get(base_url) qs_default = response_default.context["cl"].queryset response_unpublished = self.client.get(base_url + "?unpublished=1") qs_unpublished = response_unpublished.context["cl"].queryset self.assertEqual(set(qs_default), set(expected)) self.assertEqual(set(qs_unpublished), set(expected_unpublished))
def test_cms_page_toolbar_pages_link_doesnt_filter_the_page_list_by_page_id( self): """ The PageToolbar "Pages" link sends a parameter "page_id=X" which filters the page admin changelist. This is not desired behaviour for this package, the page_id for the standard cms is designed to allow the page tree to show a tree from a page i.e. expand any children below it. The page admin for this package does not use a page tree so this functionality breaks the admin changelist by only showing the page with the matching id. The PageAdmin page list should not be affected by the page_id parameter. """ template_1 = get_cms_setting('TEMPLATES')[0][0] pages = PageContentWithVersionFactory.create_batch(6, template=template_1, language="en") base_url = self.get_admin_url(PageContent, "changelist") simulated_toolbar_pages_link = "/en/admin/cms/pagecontent/?language=en&page_id=1" with self.login_user_context(self.get_superuser()): # Default changelist link response = self.client.get(base_url) # Toolbar pages link simulation response_with_page_id = self.client.get( simulated_toolbar_pages_link) self.assertSetEqual(set(response.context["cl"].queryset), set(pages)) self.assertSetEqual(set(response_with_page_id.context["cl"].queryset), set(pages))
def test_language_filter(self): expected_en = PageContentWithVersionFactory.create_batch(3, language="en") expected_de = PageContentWithVersionFactory.create_batch(3, language="de") model = PageContent base_url = self.get_admin_url(model, "changelist") with self.login_user_context(self.get_superuser()): # en is the default language configured for the site response_default = self.client.get(base_url) qs_default = response_default.context["cl"].queryset response_en = self.client.get(base_url + "?language=en") qs_en = response_en.context["cl"].queryset response_de = self.client.get(base_url + "?language=de") qs_de = response_de.context["cl"].queryset self.assertEqual(set(qs_default), set(expected_en)) self.assertEqual(set(qs_en), set(expected_en)) self.assertEqual(set(qs_de), set(expected_de))
def test_queryset_is_filtered_by_current_site(self): site1 = SiteFactory() site2 = SiteFactory() site1_pagecontents = PageContentWithVersionFactory.create_batch( 2, page__node__site=site1, language="en" ) site2_pagecontents = [ PageContentWithVersionFactory(page__node__site=site2, language="en") ] model = PageContent url = self.get_admin_url(model, "changelist") with self.login_user_context(self.get_superuser()): with self.settings(SITE_ID=site1.pk): response1 = self.client.get(url) with self.settings(SITE_ID=site2.pk): response2 = self.client.get(url) self.assertEqual(response1.status_code, 200) self.assertEqual(response2.status_code, 200) self.assertEqual(set(site1_pagecontents), set(response1.context["cl"].queryset)) self.assertEqual(set(site2_pagecontents), set(response2.context["cl"].queryset))