changeset 5159:7fb697267fdb

adding test case for home templates in various incantations. Also added comment about possibly creating/raising PageTraversal exception. I don't think we need it since @@file doesn't do it but...
author John Rouillard <rouilj@ieee.org>
date Fri, 22 Jul 2016 19:39:24 -0400
parents 63294ed25e84
children f8a32b7331f1
files test/test_cgi.py
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/test/test_cgi.py	Fri Jul 22 16:32:01 2016 -0400
+++ b/test/test_cgi.py	Fri Jul 22 19:39:24 2016 -0400
@@ -1139,6 +1139,21 @@
         # note that the extension is not included just the basename
         self.assertEqual("user.item", t.selectTemplate("user", "item"))
 
+
+        # make sure home templates work
+        self.assertEqual("home", t.selectTemplate(None, ""))
+        self.assertEqual("home.classlist", t.selectTemplate(None, "classlist"))
+
+        # home.item doesn't exist should return _generic.item.
+        self.assertEqual("_generic.item", t.selectTemplate(None, "item"))
+
+        # test case where there is no view so generic template can't
+        # be determined.
+        with self.assertRaises(NoTemplate) as cm:
+            t.selectTemplate("user", "")
+        self.assertEqual(cm.exception.message,
+                         '''Template "user" doesn't exist''')
+
         # there is no html/subdir/user.item.{,xml,html} so it will
         # raise NoTemplate.
         self.assertRaises(NoTemplate,
@@ -1151,6 +1166,9 @@
         # there is a self.directory + /html/subdir/user.item.html file,
         # but it is a link to self.dir /user.item.html which is outside
         # the html subdir so is rejected by the path traversal check.
+        # Prefer NoTemplate here, or should the code be changed to
+        # report a new PathTraversal exception? Could the PathTraversal
+        # exception leak useful info to an attacker??
         self.assertRaises(NoTemplate,
                           t.selectTemplate, "user", "subdir/item")
 

Roundup Issue Tracker: http://roundup-tracker.org/