class LinkPageCMSTest(TestCase): def setUp(self): # create test LinkPage self.parent_page = Site.objects.first().root_page self.link_page = LinkPage( content_type=ContentType.objects.get_for_model(LinkPage), title='RKH Website', link_url='https://www.rkh.co.uk', url_append='#testing') self.parent_page.add_child(instance=self.link_page) # log in as superuser to avoid permission issues user = get_user_model().objects._create_user(username='******', email='*****@*****.**', password='******', is_superuser=True) self.client.force_login(user) def test_add_linkpage(self): response = self.client.get('/admin/pages/add/tests/linkpage/%s/' % self.parent_page.id, user='******') self.assertEqual(response.status_code, 200) def test_edit_linkpage(self): response = self.client.get('/admin/pages/%s/edit/' % self.link_page.id, user='******') self.assertEqual(response.status_code, 200) self.assertContains(response, 'value="RKH Website"') def test_view_draft_linkpage(self): response = self.client.get('/admin/pages/%s/view_draft/' % self.link_page.id, user='******') self.assertEqual(response.status_code, 200) self.assertContains( response, 'This page redirects to: https://www.rkh.co.uk#testing') def test_view_draft_linkpage_to_page(self): # First, lets update the example LinkPage to link to a page instead of # a custom URL self.link_page.link_url = '' self.link_page.link_page = self.parent_page self.link_page.save() response = self.client.get('/admin/pages/%s/view_draft/' % self.link_page.id, user='******') self.assertEqual(response.status_code, 200) self.assertContains( response, 'This page redirects to: http://localhost/#testing')
def setUp(self): # create test LinkPage self.parent_page = Site.objects.first().root_page self.link_page = LinkPage( content_type=ContentType.objects.get_for_model(LinkPage), title='RKH Website', link_url='https://www.rkh.co.uk', url_append='#testing') self.parent_page.add_child(instance=self.link_page) # log in as superuser to avoid permission issues user = get_user_model().objects._create_user(username='******', email='*****@*****.**', password='******', is_superuser=True) self.client.force_login(user)
def setUp(self): user = get_user_model().objects._create_user( username='******', email='*****@*****.**', password='******', is_staff=True, is_superuser=True) parent_page = Page.objects.get(id__exact=self.parent_page_id) link_page = LinkPage( content_type=ContentType.objects.get_for_model(LinkPage), owner=user, title='RKH Website', link_url='https://www.rkh.co.uk', url_append='#testing' ) parent_page.add_child(instance=link_page) self.link_page_id = link_page.id
def setUp(self): # Create a few of link pages for testing site = Site.objects.select_related('root_page').get(is_default_site=True) self.site = site linkpage_to_page = LinkPage( title='Find out about Spiderman', link_page_id=30, url_append='?somevar=value' ) site.root_page.add_child(instance=linkpage_to_page) # Check that the above page was saved and has field values we expect self.assertTrue(linkpage_to_page.id) self.assertTrue(linkpage_to_page.show_in_menus) self.assertTrue(linkpage_to_page.show_in_menus_custom()) self.assertEqual(linkpage_to_page.get_sitemap_urls(), []) self.linkpage_to_page = linkpage_to_page linkpage_to_url = LinkPage( title='Do a google search', link_url="https://www.google.co.uk", url_append='?somevar=value', extra_classes='google external', ) site.root_page.add_child(instance=linkpage_to_url) # Check that the above page was saved and has field values we expect self.assertTrue(linkpage_to_url.id) self.assertTrue(linkpage_to_url.show_in_menus) self.assertTrue(linkpage_to_url.show_in_menus_custom()) self.assertEqual(linkpage_to_url.get_sitemap_urls(), []) self.linkpage_to_url = linkpage_to_url linkpage_to_non_routable_page = LinkPage( title='Go to this unroutable page', link_page_id=2, url_append='?somevar=value' ) site.root_page.add_child(instance=linkpage_to_non_routable_page) self.linkpage_to_non_routable_page = linkpage_to_non_routable_page