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