test_python_basic.py (853:a8359dce963e) test_python_basic.py (1017:887a4bbabf1e)
1import unittest
2import unit
3
1import unittest
2import unit
3
4class TestUnitPythonBasic(unit.TestUnitControl):
5
4
5class TestUnitPythonBasic(unit.TestUnitControl):
6 def setUpClass():
7 unit.TestUnit().check_modules('python')
8
9 conf_app = {
10 "app": {
11 "type": "python",
6 def setUpClass():
7 unit.TestUnit().check_modules('python')
8
9 conf_app = {
10 "app": {
11 "type": "python",
12 "processes": { "spare": 0 },
12 "processes": {"spare": 0},
13 "path": "/app",
13 "path": "/app",
14 "module": "wsgi"
14 "module": "wsgi",
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_python_get_empty(self):
21 }
22
23 def test_python_get_empty(self):
28 self.assertEqual(self.conf_get(),
29 {'listeners': {}, 'applications': {}}, 'empty')
24 self.assertEqual(
25 self.conf_get(), {'listeners': {}, 'applications': {}}, 'empty'
26 )
30
31 def test_python_get_prefix_listeners(self):
32 self.assertEqual(self.conf_get('listeners'), {}, 'listeners prefix')
33
34 def test_python_get_prefix_applications(self):
27
28 def test_python_get_prefix_listeners(self):
29 self.assertEqual(self.conf_get('listeners'), {}, 'listeners prefix')
30
31 def test_python_get_prefix_applications(self):
35 self.assertEqual(self.conf_get('applications'), {}, 'applications prefix')
32 self.assertEqual(
33 self.conf_get('applications'), {}, 'applications prefix'
34 )
36
37 def test_python_get_applications(self):
38 self.conf(self.conf_app, 'applications')
39
40 conf = self.conf_get()
41
42 self.assertEqual(conf['listeners'], {}, 'listeners')
35
36 def test_python_get_applications(self):
37 self.conf(self.conf_app, 'applications')
38
39 conf = self.conf_get()
40
41 self.assertEqual(conf['listeners'], {}, 'listeners')
43 self.assertEqual(conf['applications'],
42 self.assertEqual(
43 conf['applications'],
44 {
45 "app": {
46 "type": "python",
44 {
45 "app": {
46 "type": "python",
47 "processes": { "spare": 0 },
47 "processes": {"spare": 0},
48 "path": "/app",
48 "path": "/app",
49 "module": "wsgi"
49 "module": "wsgi",
50 }
51 },
50 }
51 },
52 'applications')
52 'applications',
53 )
53
54 def test_python_get_applications_prefix(self):
55 self.conf(self.conf_app, 'applications')
56
54
55 def test_python_get_applications_prefix(self):
56 self.conf(self.conf_app, 'applications')
57
57 self.assertEqual(self.conf_get('applications'),
58 self.assertEqual(
59 self.conf_get('applications'),
58 {
59 "app": {
60 "type": "python",
60 {
61 "app": {
62 "type": "python",
61 "processes": { "spare": 0 },
63 "processes": {"spare": 0},
62 "path": "/app",
64 "path": "/app",
63 "module":"wsgi"
65 "module": "wsgi",
64 }
65 },
66 }
67 },
66 'applications prefix')
68 'applications prefix',
69 )
67
68 def test_python_get_applications_prefix_2(self):
69 self.conf(self.conf_app, 'applications')
70
70
71 def test_python_get_applications_prefix_2(self):
72 self.conf(self.conf_app, 'applications')
73
71 self.assertEqual(self.conf_get('applications/app'),
74 self.assertEqual(
75 self.conf_get('applications/app'),
72 {
73 "type": "python",
76 {
77 "type": "python",
74 "processes": { "spare": 0 },
78 "processes": {"spare": 0},
75 "path": "/app",
79 "path": "/app",
76 "module": "wsgi"
80 "module": "wsgi",
77 },
81 },
78 'applications prefix 2')
82 'applications prefix 2',
83 )
79
80 def test_python_get_applications_prefix_3(self):
81 self.conf(self.conf_app, 'applications')
82
84
85 def test_python_get_applications_prefix_3(self):
86 self.conf(self.conf_app, 'applications')
87
83 self.assertEqual(self.conf_get('applications/app/type'), 'python',
84 'type')
85 self.assertEqual(self.conf_get('applications/app/processes/spare'), 0,
86 'spare')
88 self.assertEqual(
89 self.conf_get('applications/app/type'), 'python', 'type'
90 )
91 self.assertEqual(
92 self.conf_get('applications/app/processes/spare'), 0, 'spare'
93 )
87
88 def test_python_get_listeners(self):
89 self.conf(self.conf_basic)
90
94
95 def test_python_get_listeners(self):
96 self.conf(self.conf_basic)
97
91 self.assertEqual(self.conf_get()['listeners'],
92 {"*:7080":{"application":"app"}}, 'listeners')
98 self.assertEqual(
99 self.conf_get()['listeners'],
100 {"*:7080": {"application": "app"}},
101 'listeners',
102 )
93
94 def test_python_get_listeners_prefix(self):
95 self.conf(self.conf_basic)
96
103
104 def test_python_get_listeners_prefix(self):
105 self.conf(self.conf_basic)
106
97 self.assertEqual(self.conf_get('listeners'),
98 {"*:7080":{"application":"app"}}, 'listeners prefix')
107 self.assertEqual(
108 self.conf_get('listeners'),
109 {"*:7080": {"application": "app"}},
110 'listeners prefix',
111 )
99
100 def test_python_get_listeners_prefix_2(self):
101 self.conf(self.conf_basic)
102
112
113 def test_python_get_listeners_prefix_2(self):
114 self.conf(self.conf_basic)
115
103 self.assertEqual(self.conf_get('listeners/*:7080'),
104 {"application":"app"}, 'listeners prefix 2')
116 self.assertEqual(
117 self.conf_get('listeners/*:7080'),
118 {"application": "app"},
119 'listeners prefix 2',
120 )
105
106 def test_python_change_listener(self):
107 self.conf(self.conf_basic)
121
122 def test_python_change_listener(self):
123 self.conf(self.conf_basic)
108 self.conf({"*:7081":{"application":"app"}}, 'listeners')
124 self.conf({"*:7081": {"application": "app"}}, 'listeners')
109
125
110 self.assertEqual(self.conf_get('listeners'),
111 {"*:7081": {"application":"app"}}, 'change listener')
126 self.assertEqual(
127 self.conf_get('listeners'),
128 {"*:7081": {"application": "app"}},
129 'change listener',
130 )
112
113 def test_python_add_listener(self):
114 self.conf(self.conf_basic)
131
132 def test_python_add_listener(self):
133 self.conf(self.conf_basic)
115 self.conf({"application":"app"}, 'listeners/*:7082')
134 self.conf({"application": "app"}, 'listeners/*:7082')
116
135
117 self.assertEqual(self.conf_get('listeners'),
136 self.assertEqual(
137 self.conf_get('listeners'),
118 {
138 {
119 "*:7080": {
120 "application": "app"
121 },
122 "*:7082": {
123 "application": "app"
124 }
139 "*:7080": {"application": "app"},
140 "*:7082": {"application": "app"},
125 },
141 },
126 'add listener')
142 'add listener',
143 )
127
128 def test_python_change_application(self):
129 self.conf(self.conf_basic)
130
131 self.conf('30', 'applications/app/processes/max')
144
145 def test_python_change_application(self):
146 self.conf(self.conf_basic)
147
148 self.conf('30', 'applications/app/processes/max')
132 self.assertEqual(self.conf_get('applications/app/processes/max'), 30,
133 'change application max')
149 self.assertEqual(
150 self.conf_get('applications/app/processes/max'),
151 30,
152 'change application max',
153 )
134
135 self.conf('"/www"', 'applications/app/path')
154
155 self.conf('"/www"', 'applications/app/path')
136 self.assertEqual(self.conf_get('applications/app/path'), '/www',
137 'change application path')
156 self.assertEqual(
157 self.conf_get('applications/app/path'),
158 '/www',
159 'change application path',
160 )
138
139 def test_python_delete(self):
140 self.conf(self.conf_basic)
141
161
162 def test_python_delete(self):
163 self.conf(self.conf_basic)
164
142 self.assertIn('error', self.conf_delete('applications/app'),
143 'delete app before listener')
144 self.assertIn('success', self.conf_delete('listeners/*:7080'),
145 'delete listener')
146 self.assertIn('success', self.conf_delete('applications/app'),
147 'delete app after listener')
148 self.assertIn('error', self.conf_delete('applications/app'),
149 'delete app again')
165 self.assertIn(
166 'error',
167 self.conf_delete('applications/app'),
168 'delete app before listener',
169 )
170 self.assertIn(
171 'success', self.conf_delete('listeners/*:7080'), 'delete listener'
172 )
173 self.assertIn(
174 'success',
175 self.conf_delete('applications/app'),
176 'delete app after listener',
177 )
178 self.assertIn(
179 'error', self.conf_delete('applications/app'), 'delete app again'
180 )
150
181
182
151if __name__ == '__main__':
152 TestUnitPythonBasic.main()
183if __name__ == '__main__':
184 TestUnitPythonBasic.main()