Commit ffa5e79d authored by Georgios Dagkakis's avatar Georgios Dagkakis

testERP5Web: add a test for the redirection of a document published in web mode

with its reference and containing trailing slash.
301 redirection should be raised to the url without slash.

Also, fix test_WebSection_add_trailing_slash_in_url since now it expects
permanent redirection (301)
parent 2d797ea0
......@@ -42,6 +42,7 @@ from Products.ERP5Type.tests.utils import createZODBPythonScript
LANGUAGE_LIST = ('en', 'fr', 'de', 'bg', )
HTTP_OK = 200
MOVED_PERMANENTLY = 301
MOVED_TEMPORARILY = 302
......@@ -236,7 +237,7 @@ class TestERP5Web(ERP5TypeTestCase):
return webpage_list
def test_WebSection_add_trailing_slash_in_url(self):
def test_WebSection_add_trailing_slash_to_url(self):
"""
When accessing an ERP5 web section without a trailing / in the URL, the
browser will calculate absolute URL from the parent document and not the web
......@@ -255,41 +256,121 @@ class TestERP5Web(ERP5TypeTestCase):
But http://foo.com/web_site_module/bar/view should not redirect
"""
# Web Site as context
website = self.setupWebSite()
response = self.publish(website.absolute_url_path()[:-1])
self.assertEqual(MOVED_TEMPORARILY, response.status)
web_site = self.setupWebSite()
self.assertEqual(web_site.getRedirectToAddedSlash(), 0)
# first, by default redirect_to_added_slash should be 0,
# so no redirect is expected
response = self.publish(web_site.absolute_url_path()[:-1])
self.assertEqual(HTTP_OK, response.status)
response = self.publish(
"%s?ignore_layout:int=1" % website.absolute_url_path()[:-1])
self.assertEqual("%s?ignore_layout:int=1" % website.absolute_url(),
response.headers.get("location"))
self.assertEqual(MOVED_TEMPORARILY, response.status)
"%s?ignore_layout:int=1" % web_site.absolute_url_path()[:-1]
)
self.assertEqual(HTTP_OK, response.status)
response = self.publish(
"%s/getTitle?ignore_layout:int=1" % web_site.absolute_url_path()
)
# Web Section as context, Web Section acquires redirect_to_added_slash from
# Web Site, no redirects expected
web_section = self.setupWebSection()
response = self.publish(
"%s?ignore_layout:int=1" % web_section.absolute_url_path()[:-1]
)
self.assertEqual(HTTP_OK, response.status)
# set redirect_to_added_slash to 1, so that redirects are expected
web_site.setRedirectToAddedSlash(1)
response = self.publish(web_site.absolute_url_path()[:-1])
self.assertEqual(MOVED_PERMANENTLY, response.status)
response = self.publish(
"%s?ignore_layout:int=1" % web_site.absolute_url_path()[:-1]
)
self.assertEqual("%s?ignore_layout:int=1" % web_site.absolute_url(),
response.headers.get("location")
)
self.assertEqual(MOVED_PERMANENTLY, response.status)
response = self.publish(
"%s/getTitle?ignore_layout:int=1" % website.absolute_url_path())
"%s/getTitle?ignore_layout:int=1" % web_site.absolute_url_path())
self.assertEqual(HTTP_OK, response.status)
self.assertEqual("test", response.body)
response = self.publish(
"%s/getTitle" % website.absolute_url_path())
"%s/getTitle" % web_site.absolute_url_path())
self.assertEqual(HTTP_OK, response.status)
self.assertEqual("test", response.body)
response = self.publish(
"%s/a_non_existing_page" % website.absolute_url_path())
"%s/a_non_existing_page" % web_site.absolute_url_path()
)
self.assertEqual(404, response.status)
# Web Section as context
websection = self.setupWebSection()
# Web Section as context, Web Section acquires redirect_to_added_slash from
# Web Site, so that redirects expected
response = self.publish(
"%s?ignore_layout:int=1" % websection.absolute_url_path()[:-1])
self.assertEqual("%s?ignore_layout:int=1" % websection.absolute_url(),
"%s?ignore_layout:int=1" % web_section.absolute_url_path()[:-1])
self.assertEqual("%s?ignore_layout:int=1" % web_section.absolute_url(),
response.headers.get("location"))
self.assertEqual(MOVED_TEMPORARILY, response.status)
self.assertEqual(MOVED_PERMANENTLY, response.status)
response = self.publish(
"%s/getTitle?ignore_layout:int=1" % websection.absolute_url_path())
"%s/getTitle?ignore_layout:int=1" % web_section.absolute_url_path())
self.assertEqual(HTTP_OK, response.status)
self.assertEqual("1", response.body)
response = self.publish(
"%s/getTitle" % websection.absolute_url_path())
"%s/getTitle" % web_section.absolute_url_path())
self.assertEqual(HTTP_OK, response.status)
self.assertEqual("1", response.body)
# set redirect_to_added_slash to 0 for Web Section,
# so that redirects are expected (does not acquire anymore)
web_section.setRedirectToAddedSlash(0)
response = self.publish(
"%s?ignore_layout:int=1" % web_section.absolute_url_path()[:-1]
)
self.assertEqual(HTTP_OK, response.status)
def test_Document_remove_trailing_slash_from_url(self):
'''
When we publish a document using its reference and a trailing slash
we raise 301 redirect to the url excluding the slash
This is different than Web Section.
But in Web Page we need no-slash since we would render all other sources
in the container Web Section, so keeping the caches
'''
web_site = self.setupWebSite()
web_section = self.setupWebSection()
web_page_reference = 'foo_web_page'
web_page = self.web_page_module.newContent(
portal_type='Web Page',
reference=web_page_reference,
text_content='<b>OK</b>'
)
web_page.publish()
self.tic()
# Web Site as context
url_without_slash = web_site.absolute_url_path() + web_page_reference
url_with_slash = url_without_slash + '/'
response = self.publish(url_without_slash)
self.assertEqual(HTTP_OK, response.status)
response = self.publish(url_with_slash)
self.assertEqual(MOVED_PERMANENTLY, response.status)
self.assertEqual(
web_site.absolute_url() + web_page_reference,
response.headers.get("location")
)
# Web Section as context
url_without_slash = web_section.absolute_url_path() + web_page_reference
url_with_slash = url_without_slash + '/'
response = self.publish(url_without_slash)
self.assertEqual(HTTP_OK, response.status)
response = self.publish(url_with_slash)
self.assertEqual(MOVED_PERMANENTLY, response.status)
self.assertEqual(
web_section.absolute_url() + web_page_reference,
response.headers.get("location")
)
def test_01_WebSiteRecatalog(self):
"""
Test that a recataloging works for Web Site documents
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment