test_php_targets.py (1527:89bc2fef480b) test_php_targets.py (1596:b7e2d4d92624)
1from unit.applications.lang.php import TestApplicationPHP
1from unit.applications.lang.php import TestApplicationPHP
2from conftest import option
2
3
4
3class TestPHPTargets(TestApplicationPHP):
4 prerequisites = {'modules': {'php': 'any'}}
5
6 def test_php_application_targets(self):
5class TestPHPTargets(TestApplicationPHP):
6 prerequisites = {'modules': {'php': 'any'}}
7
8 def test_php_application_targets(self):
7 self.assertIn(
8 'success',
9 self.conf(
10 {
11 "listeners": {"*:7080": {"pass": "routes"}},
12 "routes": [
13 {
14 "match": {"uri": "/1"},
15 "action": {"pass": "applications/targets/1"},
16 },
17 {
18 "match": {"uri": "/2"},
19 "action": {"pass": "applications/targets/2"},
20 },
21 {"action": {"pass": "applications/targets/default"}},
22 ],
23 "applications": {
9 assert 'success' in self.conf(
10 {
11 "listeners": {"*:7080": {"pass": "routes"}},
12 "routes": [
13 {
14 "match": {"uri": "/1"},
15 "action": {"pass": "applications/targets/1"},
16 },
17 {
18 "match": {"uri": "/2"},
19 "action": {"pass": "applications/targets/2"},
20 },
21 {"action": {"pass": "applications/targets/default"}},
22 ],
23 "applications": {
24 "targets": {
25 "type": "php",
26 "processes": {"spare": 0},
24 "targets": {
27 "targets": {
25 "type": "php",
26 "processes": {"spare": 0},
27 "targets": {
28 "1": {
29 "script": "1.php",
30 "root": self.current_dir + "/php/targets",
31 },
32 "2": {
33 "script": "2.php",
34 "root": self.current_dir
35 + "/php/targets/2",
36 },
37 "default": {
38 "index": "index.php",
39 "root": self.current_dir + "/php/targets",
40 },
28 "1": {
29 "script": "1.php",
30 "root": option.test_dir + "/php/targets",
41 },
31 },
42 }
43 },
44 }
45 ),
32 "2": {
33 "script": "2.php",
34 "root": option.test_dir + "/php/targets/2",
35 },
36 "default": {
37 "index": "index.php",
38 "root": option.test_dir + "/php/targets",
39 },
40 },
41 }
42 },
43 }
46 )
47
44 )
45
48 self.assertEqual(self.get(url='/1')['body'], '1')
49 self.assertEqual(self.get(url='/2')['body'], '2')
50 self.assertEqual(self.get(url='/blah')['status'], 503) # TODO 404
51 self.assertEqual(self.get(url='/')['body'], 'index')
46 assert self.get(url='/1')['body'] == '1'
47 assert self.get(url='/2')['body'] == '2'
48 assert self.get(url='/blah')['status'] == 503 # TODO 404
49 assert self.get(url='/')['body'] == 'index'
52
50
53 self.assertIn(
54 'success',
55 self.conf(
56 "\"1.php\"", 'applications/targets/targets/default/index'
57 ),
58 'change targets index',
59 )
60 self.assertEqual(self.get(url='/')['body'], '1')
51 assert 'success' in self.conf(
52 "\"1.php\"", 'applications/targets/targets/default/index'
53 ), 'change targets index'
54 assert self.get(url='/')['body'] == '1'
61
55
62 self.assertIn(
63 'success',
64 self.conf_delete('applications/targets/targets/default/index'),
65 'remove targets index',
66 )
67 self.assertEqual(self.get(url='/')['body'], 'index')
56 assert 'success' in self.conf_delete(
57 'applications/targets/targets/default/index'
58 ), 'remove targets index'
59 assert self.get(url='/')['body'] == 'index'
68
69 def test_php_application_targets_error(self):
60
61 def test_php_application_targets_error(self):
70 self.assertIn(
71 'success',
72 self.conf(
73 {
74 "listeners": {
75 "*:7080": {"pass": "applications/targets/default"}
76 },
77 "applications": {
62 assert 'success' in self.conf(
63 {
64 "listeners": {
65 "*:7080": {"pass": "applications/targets/default"}
66 },
67 "applications": {
68 "targets": {
69 "type": "php",
70 "processes": {"spare": 0},
78 "targets": {
71 "targets": {
79 "type": "php",
80 "processes": {"spare": 0},
81 "targets": {
82 "default": {
83 "index": "index.php",
84 "root": self.current_dir + "/php/targets",
85 },
72 "default": {
73 "index": "index.php",
74 "root": option.test_dir + "/php/targets",
86 },
75 },
87 }
88 },
89 }
90 ),
91 'initial configuration',
92 )
93 self.assertEqual(self.get()['status'], 200)
76 },
77 }
78 },
79 }
80 ), 'initial configuration'
81 assert self.get()['status'] == 200
94
82
95 self.assertIn(
96 'error',
97 self.conf(
98 {"pass": "applications/targets/blah"}, 'listeners/*:7080'
99 ),
100 'invalid targets pass',
101 )
102 self.assertIn(
103 'error',
104 self.conf(
105 '"' + self.current_dir + '/php/targets\"',
106 'applications/targets/root',
107 ),
108 'invalid root',
109 )
110 self.assertIn(
111 'error',
112 self.conf('"index.php"', 'applications/targets/index'),
113 'invalid index',
114 )
115 self.assertIn(
116 'error',
117 self.conf('"index.php"', 'applications/targets/script'),
118 'invalid script',
119 )
120 self.assertIn(
121 'error',
122 self.conf_delete('applications/targets/default/root'),
123 'root remove',
124 )
125
126
127if __name__ == '__main__':
128 TestPHPTargets.main()
83 assert 'error' in self.conf(
84 {"pass": "applications/targets/blah"}, 'listeners/*:7080'
85 ), 'invalid targets pass'
86 assert 'error' in self.conf(
87 '"' + option.test_dir + '/php/targets\"',
88 'applications/targets/root',
89 ), 'invalid root'
90 assert 'error' in self.conf(
91 '"index.php"', 'applications/targets/index'
92 ), 'invalid index'
93 assert 'error' in self.conf(
94 '"index.php"', 'applications/targets/script'
95 ), 'invalid script'
96 assert 'error' in self.conf_delete(
97 'applications/targets/default/root'
98 ), 'root remove'