1import unittest 2import unit 3 4class TestUnitBasic(unit.TestUnitControl): 5 6 def setUpClass(): 7 unit.TestUnit().check_modules('python') 8 9 conf_app = { 10 "app": { 11 "type": "python", 12 "workers": 1, 13 "path": "/app", 14 "module": "wsgi" 15 } 16 } 17 18 conf_basic = { 19 "listeners": { 20 "*:7080": { 21 "application": "app" 22 } 23 }, 24 "applications": conf_app 25 } 26 27 def test_python_get_empty(self): 28 self.assertEqual(self.conf_get(), 29 {'listeners': {}, 'applications': {}}, 'empty') 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): 35 self.assertEqual(self.conf_get('/applications'), {}, 'applications prefix') 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') 43 self.assertEqual(conf['applications'], 44 { 45 "app": { 46 "type": "python", 47 "workers": 1, 48 "path": "/app", 49 "module": "wsgi" 50 } 51 }, 52 'applications') 53 54 def test_python_get_applications_prefix(self): 55 self.conf(self.conf_app, '/applications') 56 57 self.assertEqual(self.conf_get('/applications'), 58 { 59 "app": { 60 "type": "python", 61 "workers": 1, 62 "path": "/app", 63 "module":"wsgi" 64 } 65 }, 66 'applications prefix') 67 68 def test_python_get_applications_prefix_2(self): 69 self.conf(self.conf_app, '/applications') 70 71 self.assertEqual(self.conf_get('/applications/app'), 72 { 73 "type": "python", 74 "workers": 1, 75 "path": "/app", 76 "module": "wsgi" 77 }, 78 'applications prefix 2') 79 80 def test_python_get_applications_prefix_3(self): 81 self.conf(self.conf_app, '/applications') 82 83 self.assertEqual(self.conf_get('/applications/app/type'), 'python', 84 'type') 85 self.assertEqual(self.conf_get('/applications/app/workers'), 1, 86 'workers') 87 88 def test_python_get_listeners(self): 89 self.conf(self.conf_basic) 90 91 self.assertEqual(self.conf_get()['listeners'], 92 {"*:7080":{"application":"app"}}, 'listeners') 93 94 def test_python_get_listeners_prefix(self): 95 self.conf(self.conf_basic) 96 97 self.assertEqual(self.conf_get('/listeners'), 98 {"*:7080":{"application":"app"}}, 'listeners prefix') 99 100 def test_python_get_listeners_prefix_2(self): 101 self.conf(self.conf_basic) 102 103 self.assertEqual(self.conf_get('/listeners/*:7080'), 104 {"application":"app"}, 'listeners prefix 2') 105 106 def test_python_change_listener(self): 107 self.conf(self.conf_basic) 108 self.conf({"*:7081":{"application":"app"}}, '/listeners') 109 110 self.assertEqual(self.conf_get('/listeners'), 111 {"*:7081": {"application":"app"}}, 'change listener') 112 113 def test_python_add_listener(self): 114 self.conf(self.conf_basic) 115 self.conf({"application":"app"}, '/listeners/*:7082') 116 117 self.assertEqual(self.conf_get('/listeners'), 118 { 119 "*:7080": { 120 "application": "app" 121 }, 122 "*:7082": { 123 "application": "app" 124 } 125 }, 126 'add listener') 127 128 def test_python_change_application(self): 129 self.conf(self.conf_basic) 130 131 self.conf('30', '/applications/app/workers') 132 self.assertEqual(self.conf_get('/applications/app/workers'), 30, 133 'change application workers') 134 135 self.conf('"/www"', '/applications/app/path') 136 self.assertEqual(self.conf_get('/applications/app/path'), '/www', 137 'change application path') 138 139 def test_python_delete(self): 140 self.conf(self.conf_basic) 141 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') 150 151if __name__ == '__main__': 152 unittest.main() 153