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