1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import unittest
import routes
class TestEnvironment(unittest.TestCase):
def setUp(self):
m = routes.Mapper()
m.minimization = True
m.connect('archive/:year/:month/:day', controller='blog', action='view', month=None, day=None,
requirements={'month':'\d{1,2}','day':'\d{1,2}'})
m.connect('viewpost/:id', controller='post', action='view')
m.connect(':controller/:action/:id')
m.create_regs(['content', 'blog'])
con = routes.request_config()
con.mapper = m
self.con = con
def test_env_set(self):
env = dict(PATH_INFO='/content', HTTP_HOST='somewhere.com')
con = self.con
con.mapper_dict = {}
assert con.mapper_dict == {}
delattr(con, 'mapper_dict')
assert not hasattr(con, 'mapper_dict')
con.mapper_dict = {}
con.environ = env
assert con.mapper.environ == env
assert con.protocol == 'http'
assert con.host == 'somewhere.com'
assert con.mapper_dict.has_key('controller')
assert con.mapper_dict['controller'] == 'content'
if __name__ == '__main__':
unittest.main()
|