xref: /unit/test/test_python_basic.py (revision 1467:195fe0a92670)
1from unit.control import TestControl
2
3
4class TestPythonBasic(TestControl):
5    prerequisites = {'modules': {'python': 'any'}}
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": {"pass": "applications/app"}},
18        "applications": conf_app,
19    }
20
21    def test_python_get_empty(self):
22        self.assertEqual(self.conf_get(), {'listeners': {}, 'applications': {}})
23        self.assertEqual(self.conf_get('listeners'), {})
24        self.assertEqual(self.conf_get('applications'), {})
25
26    def test_python_get_applications(self):
27        self.conf(self.conf_app, 'applications')
28
29        conf = self.conf_get()
30
31        self.assertEqual(conf['listeners'], {}, 'listeners')
32        self.assertEqual(
33            conf['applications'],
34            {
35                "app": {
36                    "type": "python",
37                    "processes": {"spare": 0},
38                    "path": "/app",
39                    "module": "wsgi",
40                }
41            },
42            'applications',
43        )
44
45        self.assertEqual(
46            self.conf_get('applications'),
47            {
48                "app": {
49                    "type": "python",
50                    "processes": {"spare": 0},
51                    "path": "/app",
52                    "module": "wsgi",
53                }
54            },
55            'applications prefix',
56        )
57
58        self.assertEqual(
59            self.conf_get('applications/app'),
60            {
61                "type": "python",
62                "processes": {"spare": 0},
63                "path": "/app",
64                "module": "wsgi",
65            },
66            'applications prefix 2',
67        )
68
69        self.assertEqual(
70            self.conf_get('applications/app/type'), 'python', 'type'
71        )
72        self.assertEqual(
73            self.conf_get('applications/app/processes/spare'), 0, 'spare'
74        )
75
76    def test_python_get_listeners(self):
77        self.conf(self.conf_basic)
78
79        self.assertEqual(
80            self.conf_get()['listeners'],
81            {"*:7080": {"pass": "applications/app"}},
82            'listeners',
83        )
84
85        self.assertEqual(
86            self.conf_get('listeners'),
87            {"*:7080": {"pass": "applications/app"}},
88            'listeners prefix',
89        )
90
91        self.assertEqual(
92            self.conf_get('listeners/*:7080'),
93            {"pass": "applications/app"},
94            'listeners prefix 2',
95        )
96
97    def test_python_change_listener(self):
98        self.conf(self.conf_basic)
99        self.conf({"*:7081": {"pass": "applications/app"}}, 'listeners')
100
101        self.assertEqual(
102            self.conf_get('listeners'),
103            {"*:7081": {"pass": "applications/app"}},
104            'change listener',
105        )
106
107    def test_python_add_listener(self):
108        self.conf(self.conf_basic)
109        self.conf({"pass": "applications/app"}, 'listeners/*:7082')
110
111        self.assertEqual(
112            self.conf_get('listeners'),
113            {
114                "*:7080": {"pass": "applications/app"},
115                "*:7082": {"pass": "applications/app"},
116            },
117            'add listener',
118        )
119
120    def test_python_change_application(self):
121        self.conf(self.conf_basic)
122
123        self.conf('30', 'applications/app/processes/max')
124        self.assertEqual(
125            self.conf_get('applications/app/processes/max'),
126            30,
127            'change application max',
128        )
129
130        self.conf('"/www"', 'applications/app/path')
131        self.assertEqual(
132            self.conf_get('applications/app/path'),
133            '/www',
134            'change application path',
135        )
136
137    def test_python_delete(self):
138        self.conf(self.conf_basic)
139
140        self.assertIn('error', self.conf_delete('applications/app'))
141        self.assertIn('success', self.conf_delete('listeners/*:7080'))
142        self.assertIn('success', self.conf_delete('applications/app'))
143        self.assertIn('error', self.conf_delete('applications/app'))
144
145    def test_python_delete_blocks(self):
146        self.conf(self.conf_basic)
147
148        self.assertIn('success', self.conf_delete('listeners'))
149        self.assertIn('success', self.conf_delete('applications'))
150
151        self.assertIn('success', self.conf(self.conf_app, 'applications'))
152        self.assertIn(
153            'success',
154            self.conf({"*:7081": {"pass": "applications/app"}}, 'listeners'),
155            'applications restore',
156        )
157
158
159if __name__ == '__main__':
160    TestPythonBasic.main()
161