def test_move_page_from_one_index_to_another_creates_redirect_for_child( client, site, ): test_index_page_1 = factories.AutomaticRedirectsTestIndexPageFactory( parent=site.root_page, title='Automatic redirects test index page 1', slug='index-page-1', subtitle='Test subtitle', body='<p>Test body</p>', ) response = client.get(test_index_page_1.get_url()) assert response.status_code == 200 test_index_page_2 = factories.AutomaticRedirectsTestIndexPageFactory( parent=site.root_page, title='Automatic redirects test index page 2', slug='index-page-2', subtitle='Test subtitle', body='<p>Test body</p>', ) response = client.get(test_index_page_2.get_url()) assert response.status_code == 200 test_page = factories.AutomaticRedirectsTestPageFactory( parent=test_index_page_1, title='Test Page', slug='test-page') response = client.get(test_page.get_url()) assert response.status_code == 200 test_page_child = factories.AutomaticRedirectsTestPageFactory( parent=test_page, title='Test Page Child', slug='test-page-child') test_page_child_url_pre_move = test_page_child.get_url() response = client.get(test_page_child_url_pre_move) assert response.status_code == 200 test_page.move(test_index_page_2, 'last-child') test_page_child.refresh_from_db() test_page_child_url_post_move = test_page_child.get_url() assert test_index_page_1.get_descendants().count() == 0 assert test_index_page_2.get_descendants().count() == 2 assert test_index_page_1.get_url() not in test_page_child_url_post_move assert test_index_page_2.get_url() in test_page_child_url_post_move response = client.get(test_page_child_url_post_move) assert response.status_code == 200 response = client.get(test_page_child_url_pre_move) assert response.status_code == 301
def test_only_published_pages_gets_redirected(self): test_index_page = factories.AutomaticRedirectsTestIndexPageFactory( parent=self.site.root_page, title='Automatic redirects test index page', slug='index-page', subtitle='Test subtitle', body='<p>Test body</p>', ) assert test_index_page.live == True test_sub_index_page = factories.AutomaticRedirectsTestIndexPageFactory( parent=test_index_page, title='Automatic redirects test index page', slug='index-page', subtitle='Test subtitle', body='<p>Test body</p>', ) test_page1 = factories.AutomaticRedirectsTestPageFactory( parent=test_sub_index_page, title='Test Page 1', slug='test-page-1') test_page1.unpublish() self.client.login(username=self.user.username, password='******') == True resp = self.client.post( reverse('wagtailadmin_pages:move_confirm', args=(test_page1.id, test_index_page.id)), ) assert Redirect.objects.count() == 0
def test_index_page_slug_change_create_redirects_child_pages(client, site): test_index_page = factories.AutomaticRedirectsTestIndexPageFactory( parent=site.root_page, title='Automatic redirects test index page', slug='index-page', subtitle='Test subtitle', body='<p>Test body</p>', ) test_page1 = factories.AutomaticRedirectsTestPageFactory( parent=test_index_page, title='Test Page 1', slug='test-page-1') test_page2 = factories.AutomaticRedirectsTestPageFactory( parent=test_index_page, title='Test Page 2', slug='test-page-2') response = client.get(test_page1.url) assert response.status_code == 200 response = client.get(test_page2.url) assert response.status_code == 200 # Change slug old_url = test_index_page.url test_index_page.slug = 'index-page-new' publish_page(test_index_page) # New url will give 200 response = client.get('/index-page-new/') assert response.status_code == 200 response = client.get('/index-page-new/test-page-1/') assert response.status_code == 200 response = client.get('/index-page-new/test-page-2/') assert response.status_code == 200 # Old urls will give 301 Permanent Redirect response = client.get(old_url) assert response.status_code == 301 response = client.get('/index-page/test-page-1/') assert response.status_code == 301 response = client.get('/index-page/test-page-2/') assert response.status_code == 301
def test_moving_parent_created_redirect_for_child_as_well(self): test_index_page = factories.AutomaticRedirectsTestIndexPageFactory( parent=self.site.root_page, title='Automatic redirects test index page', slug='index-page', subtitle='Test subtitle', body='<p>Test body</p>', ) test_sub_index_page = factories.AutomaticRedirectsTestIndexPageFactory( parent=test_index_page, title='Automatic redirects test index page', slug='index-page', subtitle='Test subtitle', body='<p>Test body</p>', ) test_page1 = factories.AutomaticRedirectsTestPageFactory( parent=test_sub_index_page, title='Test Page 1', slug='test-page-1') test_child_page1 = factories.AutomaticRedirectsTestPageFactory( parent=test_page1, title='Test Child Page 1', slug='test-child-page-1') self.client.login(username=self.user.username, password='******') == True resp = self.client.post( reverse('wagtailadmin_pages:move_confirm', args=(test_page1.id, test_index_page.id)), ) assert Redirect.objects.count() == 2 response = self.client.get( '/index-page/test-page-1/test-child-page-1/') assert response.status_code == 200 response = self.client.get( '/index-page/index-page/test-page-1/test-child-page-1/') assert response.status_code == 301