Deleted Added
1from unit.applications.lang.php import TestApplicationPHP
2
3class TestPHPTargets(TestApplicationPHP):
4 prerequisites = {'modules': {'php': 'any'}}
5
6 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": {
24 "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 },
41 },
42 }
43 },
44 }
45 ),
46 )
47
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')
52
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')
61
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')
68
69 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": {
78 "targets": {
79 "type": "php",
80 "processes": {"spare": 0},
81 "targets": {
82 "default": {
83 "index": "index.php",
84 "root": self.current_dir + "/php/targets",
85 },
86 },
87 }
88 },
89 }
90 ),
91 'initial configuration',
92 )
93 self.assertEqual(self.get()['status'], 200)
94
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()