test_php_basic.py (853:a8359dce963e) test_php_basic.py (1017:887a4bbabf1e)
1import unittest
2import unit
3
1import unittest
2import unit
3
4class TestUnitPHPBasic(unit.TestUnitControl):
5
4
5class TestUnitPHPBasic(unit.TestUnitControl):
6 def setUpClass():
7 unit.TestUnit().check_modules('php')
8
9 conf_app = {
10 "app": {
11 "type": "php",
6 def setUpClass():
7 unit.TestUnit().check_modules('php')
8
9 conf_app = {
10 "app": {
11 "type": "php",
12 "processes": { "spare": 0 },
12 "processes": {"spare": 0},
13 "root": "/app",
13 "root": "/app",
14 "index": "index.php"
14 "index": "index.php",
15 }
16 }
17
18 conf_basic = {
15 }
16 }
17
18 conf_basic = {
19 "listeners": {
20 "*:7080": {
21 "application": "app"
22 }
23 },
24 "applications": conf_app
19 "listeners": {"*:7080": {"application": "app"}},
20 "applications": conf_app,
25 }
26
27 def test_php_get_applications(self):
28 self.conf(self.conf_app, 'applications')
29
30 conf = self.conf_get()
31
32 self.assertEqual(conf['listeners'], {}, 'listeners')
21 }
22
23 def test_php_get_applications(self):
24 self.conf(self.conf_app, 'applications')
25
26 conf = self.conf_get()
27
28 self.assertEqual(conf['listeners'], {}, 'listeners')
33 self.assertEqual(conf['applications'],
29 self.assertEqual(
30 conf['applications'],
34 {
35 "app": {
36 "type": "php",
31 {
32 "app": {
33 "type": "php",
37 "processes": { "spare": 0 },
34 "processes": {"spare": 0},
38 "root": "/app",
35 "root": "/app",
39 "index": "index.php"
36 "index": "index.php",
40 }
37 }
41 },
42 'applications')
38 },
39 'applications',
40 )
43
44 def test_php_get_applications_prefix(self):
45 self.conf(self.conf_app, 'applications')
46
41
42 def test_php_get_applications_prefix(self):
43 self.conf(self.conf_app, 'applications')
44
47 self.assertEqual(self.conf_get('applications'),
45 self.assertEqual(
46 self.conf_get('applications'),
48 {
49 "app": {
50 "type": "php",
47 {
48 "app": {
49 "type": "php",
51 "processes": { "spare": 0 },
50 "processes": {"spare": 0},
52 "root": "/app",
51 "root": "/app",
53 "index": "index.php"
52 "index": "index.php",
54 }
55 },
53 }
54 },
56 'applications prefix')
55 'applications prefix',
56 )
57
58 def test_php_get_applications_prefix_2(self):
59 self.conf(self.conf_app, 'applications')
60
57
58 def test_php_get_applications_prefix_2(self):
59 self.conf(self.conf_app, 'applications')
60
61 self.assertEqual(self.conf_get('applications/app'),
61 self.assertEqual(
62 self.conf_get('applications/app'),
62 {
63 "type": "php",
63 {
64 "type": "php",
64 "processes": { "spare": 0 },
65 "processes": {"spare": 0},
65 "root": "/app",
66 "root": "/app",
66 "index": "index.php"
67 "index": "index.php",
67 },
68 },
68 'applications prefix 2')
69 'applications prefix 2',
70 )
69
70 def test_php_get_applications_prefix_3(self):
71 self.conf(self.conf_app, 'applications')
72
71
72 def test_php_get_applications_prefix_3(self):
73 self.conf(self.conf_app, 'applications')
74
73 self.assertEqual(self.conf_get('applications/app/type'), 'php',
74 'type')
75 self.assertEqual(self.conf_get('applications/app/processes/spare'), 0,
76 'spare processes')
75 self.assertEqual(self.conf_get('applications/app/type'), 'php', 'type')
76 self.assertEqual(
77 self.conf_get('applications/app/processes/spare'),
78 0,
79 'spare processes',
80 )
77
78 def test_php_get_listeners(self):
79 self.conf(self.conf_basic)
80
81
82 def test_php_get_listeners(self):
83 self.conf(self.conf_basic)
84
81 self.assertEqual(self.conf_get()['listeners'],
82 {"*:7080":{"application":"app"}}, 'listeners')
85 self.assertEqual(
86 self.conf_get()['listeners'],
87 {"*:7080": {"application": "app"}},
88 'listeners',
89 )
83
84 def test_php_get_listeners_prefix(self):
85 self.conf(self.conf_basic)
86
90
91 def test_php_get_listeners_prefix(self):
92 self.conf(self.conf_basic)
93
87 self.assertEqual(self.conf_get('listeners'),
88 {"*:7080":{"application":"app"}}, 'listeners prefix')
94 self.assertEqual(
95 self.conf_get('listeners'),
96 {"*:7080": {"application": "app"}},
97 'listeners prefix',
98 )
89
90 def test_php_get_listeners_prefix_2(self):
91 self.conf(self.conf_basic)
92
99
100 def test_php_get_listeners_prefix_2(self):
101 self.conf(self.conf_basic)
102
93 self.assertEqual(self.conf_get('listeners/*:7080'),
94 {"application":"app"}, 'listeners prefix 2')
103 self.assertEqual(
104 self.conf_get('listeners/*:7080'),
105 {"application": "app"},
106 'listeners prefix 2',
107 )
95
96 def test_php_change_listener(self):
97 self.conf(self.conf_basic)
108
109 def test_php_change_listener(self):
110 self.conf(self.conf_basic)
98 self.conf({"*:7081":{"application":"app"}}, 'listeners')
111 self.conf({"*:7081": {"application": "app"}}, 'listeners')
99
112
100 self.assertEqual(self.conf_get('listeners'),
101 {"*:7081": {"application":"app"}}, 'change listener')
113 self.assertEqual(
114 self.conf_get('listeners'),
115 {"*:7081": {"application": "app"}},
116 'change listener',
117 )
102
103 def test_php_add_listener(self):
104 self.conf(self.conf_basic)
118
119 def test_php_add_listener(self):
120 self.conf(self.conf_basic)
105 self.conf({"application":"app"}, 'listeners/*:7082')
121 self.conf({"application": "app"}, 'listeners/*:7082')
106
122
107 self.assertEqual(self.conf_get('listeners'),
123 self.assertEqual(
124 self.conf_get('listeners'),
108 {
125 {
109 "*:7080": {
110 "application": "app"
111 },
112 "*:7082": {
113 "application": "app"
114 }
126 "*:7080": {"application": "app"},
127 "*:7082": {"application": "app"},
115 },
128 },
116 'add listener')
129 'add listener',
130 )
117
118 def test_php_change_application(self):
119 self.conf(self.conf_basic)
120
121 self.conf('30', 'applications/app/processes/max')
131
132 def test_php_change_application(self):
133 self.conf(self.conf_basic)
134
135 self.conf('30', 'applications/app/processes/max')
122 self.assertEqual(self.conf_get('applications/app/processes/max'), 30,
123 'change application max')
136 self.assertEqual(
137 self.conf_get('applications/app/processes/max'),
138 30,
139 'change application max',
140 )
124
125 self.conf('"/www"', 'applications/app/root')
141
142 self.conf('"/www"', 'applications/app/root')
126 self.assertEqual(self.conf_get('applications/app/root'), '/www',
127 'change application root')
143 self.assertEqual(
144 self.conf_get('applications/app/root'),
145 '/www',
146 'change application root',
147 )
128
129 def test_php_delete(self):
130 self.conf(self.conf_basic)
131
148
149 def test_php_delete(self):
150 self.conf(self.conf_basic)
151
132 self.assertIn('error', self.conf_delete('applications/app'),
133 'delete app before listener')
134 self.assertIn('success', self.conf_delete('listeners/*:7080'),
135 'delete listener')
136 self.assertIn('success', self.conf_delete('applications/app'),
137 'delete app after listener')
138 self.assertIn('error', self.conf_delete('applications/app'),
139 'delete app again')
152 self.assertIn(
153 'error',
154 self.conf_delete('applications/app'),
155 'delete app before listener',
156 )
157 self.assertIn(
158 'success', self.conf_delete('listeners/*:7080'), 'delete listener'
159 )
160 self.assertIn(
161 'success',
162 self.conf_delete('applications/app'),
163 'delete app after listener',
164 )
165 self.assertIn(
166 'error', self.conf_delete('applications/app'), 'delete app again'
167 )
140
168
169
141if __name__ == '__main__':
142 TestUnitPHPBasic.main()
170if __name__ == '__main__':
171 TestUnitPHPBasic.main()