1import unittest 2import unit 3 4class TestUnitBasic(unit.TestUnitControl): 5 6 def setUpClass(): 7 unit.TestUnit().check_modules('php') 8 9 def test_php_get(self): 10 resp = self.get() 11 self.assertEqual(resp, {'listeners': {}, 'applications': {}}, 'empty') 12 self.assertEqual(self.get('/listeners'), {}, 'empty listeners prefix') 13 self.assertEqual(self.get('/applications'), {}, 14 'empty applications prefix') 15 16 self.put('/applications', """ 17 { 18 "app": { 19 "type": "php", 20 "workers": 1, 21 "root": "/app", 22 "index": "index.php" 23 } 24 } 25 """) 26 27 resp = self.get() 28 29 self.assertEqual(resp['listeners'], {}, 'php empty listeners') 30 self.assertEqual(resp['applications'], 31 { 32 "app": { 33 "type": "php", 34 "workers": 1, 35 "root": "/app", 36 "index": "index.php" 37 } 38 }, 39 'php applications') 40 41 self.assertEqual(self.get('/applications'), 42 { 43 "app": { 44 "type": "php", 45 "workers": 1, 46 "root": "/app", 47 "index": "index.php" 48 } 49 }, 50 'php applications prefix') 51 52 self.assertEqual(self.get('/applications/app'), 53 { 54 "type": "php", 55 "workers": 1, 56 "root": "/app", 57 "index": "index.php" 58 }, 59 'php applications prefix 2') 60 61 self.assertEqual(self.get('/applications/app/type'), 'php', 62 'php applications type') 63 self.assertEqual(self.get('/applications/app/workers'), 1, 64 'php applications workers') 65 66 self.put('/listeners', '{"*:7080":{"application":"app"}}') 67 68 self.assertEqual(self.get()['listeners'], 69 {"*:7080":{"application":"app"}}, 'php listeners') 70 self.assertEqual(self.get('/listeners'), 71 {"*:7080":{"application":"app"}}, 'php listeners prefix') 72 self.assertEqual(self.get('/listeners/*:7080'), 73 {"application":"app"}, 'php listeners prefix 2') 74 self.assertEqual(self.get('/listeners/*:7080/application'), 'app', 75 'php listeners application') 76 77 def test_php_put(self): 78 self.put('/', """ 79 { 80 "listeners": { 81 "*:7080": { 82 "application": "app" 83 } 84 }, 85 "applications": { 86 "app": { 87 "type": "php", 88 "workers": 1, 89 "root": "/app", 90 "index": "index.php" 91 } 92 } 93 } 94 """) 95 96 resp = self.get() 97 98 self.assertEqual(resp['listeners'], {"*:7080":{"application":"app"}}, 99 'put listeners') 100 101 self.assertEqual(resp['applications'], 102 { 103 "app": { 104 "type": "php", 105 "workers": 1, 106 "root": "/app", 107 "index": "index.php" 108 } 109 }, 110 'put applications') 111 112 self.put('/listeners', '{"*:7081":{"application":"app"}}') 113 self.assertEqual(self.get('/listeners'), 114 {"*:7081": {"application":"app"}}, 'put listeners prefix') 115 116 self.put('/listeners/*:7082', '{"application":"app"}') 117 118 self.assertEqual(self.get('/listeners'), 119 { 120 "*:7081": { 121 "application": "app" 122 }, 123 "*:7082": { 124 "application": "app" 125 } 126 }, 127 'put listeners prefix 3') 128 129 self.put('/applications/app/workers', '30') 130 self.assertEqual(self.get('/applications/app/workers'), 30, 131 'put applications workers') 132 133 self.put('/applications/app/root', '"/www"') 134 self.assertEqual(self.get('/applications/app/root'), '/www', 135 'put applications root') 136 137 def test_php_delete(self): 138 self.put('/', """ 139 { 140 "listeners": { 141 "*:7080": { 142 "application": "app" 143 } 144 }, 145 "applications": { 146 "app": { 147 "type": "php", 148 "workers": 1, 149 "root": "/app", 150 "index": "index.php" 151 } 152 } 153 } 154 """) 155 156 self.assertIn('error', self.delete('/applications/app'), 157 'delete app before listener') 158 self.assertIn('success', self.delete('/listeners/*:7080'), 159 'delete listener') 160 self.assertIn('success', self.delete('/applications/app'), 161 'delete app after listener') 162 self.assertIn('error', self.delete('/applications/app'), 163 'delete app again') 164 165if __name__ == '__main__': 166 unittest.main() 167