|
| 1 | +"""Test Webware Testing context""" |
| 2 | + |
| 3 | +import unittest |
| 4 | + |
| 5 | +from .AppTest import AppTest |
| 6 | + |
| 7 | + |
| 8 | +class TestContextMap(AppTest, unittest.TestCase): |
| 9 | + |
| 10 | + settings = dict( |
| 11 | + PrintConfigAtStartUp=False, |
| 12 | + ExtraPathInfo=False, |
| 13 | + Contexts={'Testing': 'Testing', 'default': 'Testing'} |
| 14 | + ) |
| 15 | + |
| 16 | + def testStartPage(self): |
| 17 | + r = self.testApp.get('/') |
| 18 | + self.assertEqual(r.status, '200 OK') |
| 19 | + self.assertEqual(r.request.path, '/') |
| 20 | + r.mustcontain('<title>Testing</title>') |
| 21 | + |
| 22 | + def testContextPage(self): |
| 23 | + r = self.testApp.get('/Testing/') |
| 24 | + self.assertEqual(r.status, '200 OK') |
| 25 | + self.assertEqual(r.request.path, '/Testing/') |
| 26 | + r.mustcontain('<title>Testing</title>') |
| 27 | + |
| 28 | + def testBadContextPage(self): |
| 29 | + r = self.testApp.get('/default/', expect_errors=True) |
| 30 | + self.assertEqual(r.status, '404 Not Found', r.status) |
| 31 | + r = self.testApp.get('/TestAlias/', expect_errors=True) |
| 32 | + self.assertEqual(r.status, '404 Not Found', r.status) |
| 33 | + |
| 34 | + |
| 35 | +class TestAliasedContext(AppTest, unittest.TestCase): |
| 36 | + |
| 37 | + settings = dict( |
| 38 | + PrintConfigAtStartUp=False, |
| 39 | + ExtraPathInfo=False, |
| 40 | + Contexts={'TestAlias': 'Testing', 'default': 'TestAlias'} |
| 41 | + ) |
| 42 | + |
| 43 | + def testStartPage(self): |
| 44 | + r = self.testApp.get('/') |
| 45 | + self.assertEqual(r.status, '200 OK') |
| 46 | + self.assertEqual(r.request.path, '/') |
| 47 | + r.mustcontain('<title>Testing</title>') |
| 48 | + |
| 49 | + def testContextPage(self): |
| 50 | + r = self.testApp.get('/TestAlias/') |
| 51 | + self.assertEqual(r.status, '200 OK') |
| 52 | + self.assertEqual(r.request.path, '/TestAlias/') |
| 53 | + r.mustcontain('<title>Testing</title>') |
| 54 | + |
| 55 | + def testBadContextPage(self): |
| 56 | + r = self.testApp.get('/default/', expect_errors=True) |
| 57 | + self.assertEqual(r.status, '404 Not Found', r.status) |
| 58 | + r = self.testApp.get('/Testing/', expect_errors=True) |
| 59 | + self.assertEqual(r.status, '404 Not Found', r.status) |
| 60 | + |
| 61 | + |
| 62 | +class TestOnlyDefaultContext(AppTest, unittest.TestCase): |
| 63 | + |
| 64 | + settings = dict( |
| 65 | + PrintConfigAtStartUp=False, |
| 66 | + ExtraPathInfo=False, |
| 67 | + Contexts={'default': 'Testing'} |
| 68 | + ) |
| 69 | + |
| 70 | + def testStartPage(self): |
| 71 | + r = self.testApp.get('/') |
| 72 | + self.assertEqual(r.status, '200 OK') |
| 73 | + self.assertEqual(r.request.path, '/') |
| 74 | + r.mustcontain('<title>Testing</title>') |
| 75 | + |
| 76 | + def testContextPage(self): |
| 77 | + r = self.testApp.get('/default/') |
| 78 | + self.assertEqual(r.status, '200 OK') |
| 79 | + self.assertEqual(r.request.path, '/default/') |
| 80 | + r.mustcontain('<title>Testing</title>') |
| 81 | + |
| 82 | + def testBadContextPage(self): |
| 83 | + r = self.testApp.get('/Testing/', expect_errors=True) |
| 84 | + self.assertEqual(r.status, '404 Not Found', r.status) |
| 85 | + r = self.testApp.get('/TestAlias/', expect_errors=True) |
| 86 | + self.assertEqual(r.status, '404 Not Found', r.status) |
0 commit comments