Skip to content

Commit 938657d

Browse files
committed
Fix aliased contexts and add regression test
1 parent 0035c07 commit 938657d

File tree

3 files changed

+93
-8
lines changed

3 files changed

+93
-8
lines changed

webware/Tests/TestEndToEnd/AppTest.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ def setUpClass(cls):
3030
app = Application(settings=cls.settings, development=True)
3131
cls.app = app
3232
cls.testApp = TestApp(app)
33-
except Exception:
34-
error = True
33+
except Exception as e:
34+
error = str(e) or 'Could not create application'
3535
else:
36-
error = False
36+
error = None
3737
finally:
3838
output = sys.stdout.getvalue().rstrip()
3939
sys.stdout, sys.stderr = stdout, stderr
4040
if error:
4141
raise RuntimeError(
42-
'Error setting up application. Output was:\n'
43-
+ output)
42+
'Error setting up application:\n' + error +
43+
'\nOutput was:\n' + output)
4444
if (not output.startswith('Webware for Python')
4545
or 'Running in development mode' not in output
4646
or 'Loading context' not in output):
4747
raise AssertionError(
48-
'Application was not properly started. Output was:\n'
49-
+ output)
48+
'Application was not properly started.'
49+
' Output was:\n' + output)
5050

5151
@classmethod
5252
def tearDownClass(cls):
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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)

webware/URLParser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ def addContext(self, name, path):
184184
try:
185185
localDir, packageName = os.path.split(path)
186186
spec = self._imp.findSpec(packageName, localDir or '.')
187-
spec.name = name.rpartition('/')[2]
188187
try:
189188
module = self._imp.moduleFromSpec(spec)
190189
except ImportError as e:

0 commit comments

Comments
 (0)