Commit 956a4b5e authored by Georgios Dagkakis's avatar Georgios Dagkakis

testERP5Web: update the test with trailing slashes, so that it checks for different

values of redirect_to_added_slash, for the Web Site and Web Section in the test
parent 0ecfda50
...@@ -237,7 +237,7 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -237,7 +237,7 @@ class TestERP5Web(ERP5TypeTestCase):
return webpage_list 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 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 browser will calculate absolute URL from the parent document and not the web
...@@ -256,41 +256,76 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -256,41 +256,76 @@ class TestERP5Web(ERP5TypeTestCase):
But http://foo.com/web_site_module/bar/view should not redirect But http://foo.com/web_site_module/bar/view should not redirect
""" """
# Web Site as context # Web Site as context
website = self.setupWebSite() web_site = self.setupWebSite()
response = self.publish(website.absolute_url_path()[:-1]) 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" % 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) self.assertEqual(MOVED_PERMANENTLY, response.status)
response = self.publish( response = self.publish(
"%s?ignore_layout:int=1" % website.absolute_url_path()[:-1]) "%s?ignore_layout:int=1" % web_site.absolute_url_path()[:-1]
self.assertEqual("%s?ignore_layout:int=1" % website.absolute_url(), )
response.headers.get("location")) self.assertEqual("%s?ignore_layout:int=1" % web_site.absolute_url(),
response.headers.get("location")
)
self.assertEqual(MOVED_PERMANENTLY, response.status) self.assertEqual(MOVED_PERMANENTLY, response.status)
response = self.publish( 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(HTTP_OK, response.status)
self.assertEqual("test", response.body) self.assertEqual("test", response.body)
response = self.publish( response = self.publish(
"%s/getTitle" % website.absolute_url_path()) "%s/getTitle" % web_site.absolute_url_path())
self.assertEqual(HTTP_OK, response.status) self.assertEqual(HTTP_OK, response.status)
self.assertEqual("test", response.body) self.assertEqual("test", response.body)
response = self.publish( 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) 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( response = self.publish(
"%s?ignore_layout:int=1" % websection.absolute_url_path()[:-1]) "%s?ignore_layout:int=1" % web_section.absolute_url_path()[:-1])
self.assertEqual("%s?ignore_layout:int=1" % websection.absolute_url(), self.assertEqual("%s?ignore_layout:int=1" % web_section.absolute_url(),
response.headers.get("location")) response.headers.get("location"))
self.assertEqual(MOVED_PERMANENTLY, response.status) self.assertEqual(MOVED_PERMANENTLY, response.status)
response = self.publish( 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(HTTP_OK, response.status)
self.assertEqual("1", response.body) self.assertEqual("1", response.body)
response = self.publish( response = self.publish(
"%s/getTitle" % websection.absolute_url_path()) "%s/getTitle" % web_section.absolute_url_path())
self.assertEqual(HTTP_OK, response.status) self.assertEqual(HTTP_OK, response.status)
self.assertEqual("1", response.body) 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): def test_Document_remove_trailing_slash_from_url(self):
''' '''
When we publish a document using its reference and a trailing slash When we publish a document using its reference and a trailing slash
......
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