xref: /unit/test/test_python_basic.py (revision 512:29572dff1948)
1import unittest
2import unit
3
4class TestUnitBasic(unit.TestUnitControl):
5
6    def setUpClass():
7        u = unit.TestUnit()
8
9        u.check_modules('python')
10        u.check_version('0.5')
11
12    conf_app = {
13        "app": {
14            "type": "python",
15            "processes": { "spare": 0 },
16            "path": "/app",
17            "module": "wsgi"
18        }
19    }
20
21    conf_basic = {
22        "listeners": {
23            "*:7080": {
24                "application": "app"
25            }
26        },
27        "applications": conf_app
28    }
29
30    def test_python_get_empty(self):
31        self.assertEqual(self.conf_get(),
32            {'listeners': {}, 'applications': {}}, 'empty')
33
34    def test_python_get_prefix_listeners(self):
35        self.assertEqual(self.conf_get('/listeners'), {}, 'listeners prefix')
36
37    def test_python_get_prefix_applications(self):
38        self.assertEqual(self.conf_get('/applications'), {}, 'applications prefix')
39
40    def test_python_get_applications(self):
41        self.conf(self.conf_app, '/applications')
42
43        conf = self.conf_get()
44
45        self.assertEqual(conf['listeners'], {}, 'listeners')
46        self.assertEqual(conf['applications'],
47            {
48                "app": {
49                    "type": "python",
50                    "processes": { "spare": 0 },
51                    "path": "/app",
52                    "module": "wsgi"
53                }
54            },
55            'applications')
56
57    def test_python_get_applications_prefix(self):
58        self.conf(self.conf_app, '/applications')
59
60        self.assertEqual(self.conf_get('/applications'),
61            {
62                "app": {
63                    "type": "python",
64                    "processes": { "spare": 0 },
65                    "path": "/app",
66                    "module":"wsgi"
67                }
68            },
69            'applications prefix')
70
71    def test_python_get_applications_prefix_2(self):
72        self.conf(self.conf_app, '/applications')
73
74        self.assertEqual(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    def test_python_get_applications_prefix_3(self):
84        self.conf(self.conf_app, '/applications')
85
86        self.assertEqual(self.conf_get('/applications/app/type'), 'python',
87            'type')
88        self.assertEqual(self.conf_get('/applications/app/processes/spare'), 0,
89            'spare')
90
91    def test_python_get_listeners(self):
92        self.conf(self.conf_basic)
93
94        self.assertEqual(self.conf_get()['listeners'],
95            {"*:7080":{"application":"app"}}, 'listeners')
96
97    def test_python_get_listeners_prefix(self):
98        self.conf(self.conf_basic)
99
100        self.assertEqual(self.conf_get('/listeners'),
101            {"*:7080":{"application":"app"}}, 'listeners prefix')
102
103    def test_python_get_listeners_prefix_2(self):
104        self.conf(self.conf_basic)
105
106        self.assertEqual(self.conf_get('/listeners/*:7080'),
107            {"application":"app"}, 'listeners prefix 2')
108
109    def test_python_change_listener(self):
110        self.conf(self.conf_basic)
111        self.conf({"*:7081":{"application":"app"}}, '/listeners')
112
113        self.assertEqual(self.conf_get('/listeners'),
114            {"*:7081": {"application":"app"}}, 'change listener')
115
116    def test_python_add_listener(self):
117        self.conf(self.conf_basic)
118        self.conf({"application":"app"}, '/listeners/*:7082')
119
120        self.assertEqual(self.conf_get('/listeners'),
121            {
122                "*:7080": {
123                    "application": "app"
124                },
125                "*:7082": {
126                    "application": "app"
127                }
128            },
129            'add listener')
130
131    def test_python_change_application(self):
132        self.conf(self.conf_basic)
133
134        self.conf('30', '/applications/app/processes/max')
135        self.assertEqual(self.conf_get('/applications/app/processes/max'), 30,
136            'change application max')
137
138        self.conf('"/www"', '/applications/app/path')
139        self.assertEqual(self.conf_get('/applications/app/path'), '/www',
140            'change application path')
141
142    def test_python_delete(self):
143        self.conf(self.conf_basic)
144
145        self.assertIn('error', self.conf_delete('/applications/app'),
146            'delete app before listener')
147        self.assertIn('success', self.conf_delete('/listeners/*:7080'),
148            'delete listener')
149        self.assertIn('success', self.conf_delete('/applications/app'),
150            'delete app after listener')
151        self.assertIn('error', self.conf_delete('/applications/app'),
152            'delete app again')
153
154if __name__ == '__main__':
155    unittest.main()
156