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