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