1from unit.control import TestControl 2 3 4class TestPHPBasic(TestControl): 5 prerequisites = {'modules': ['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 self.assertEqual( 41 self.conf_get('applications'), 42 { 43 "app": { 44 "type": "php", 45 "processes": {"spare": 0}, 46 "root": "/app", 47 "index": "index.php", 48 } 49 }, 50 'applications prefix', 51 ) 52 53 self.assertEqual( 54 self.conf_get('applications/app'), 55 { 56 "type": "php", 57 "processes": {"spare": 0}, 58 "root": "/app", 59 "index": "index.php", 60 }, 61 'applications prefix 2', 62 ) 63 64 self.assertEqual(self.conf_get('applications/app/type'), 'php', 'type') 65 self.assertEqual( 66 self.conf_get('applications/app/processes/spare'), 67 0, 68 'spare processes', 69 ) 70 71 def test_php_get_listeners(self): 72 self.conf(self.conf_basic) 73 74 self.assertEqual( 75 self.conf_get()['listeners'], 76 {"*:7080": {"pass": "applications/app"}}, 77 'listeners', 78 ) 79 80 self.assertEqual( 81 self.conf_get('listeners'), 82 {"*:7080": {"pass": "applications/app"}}, 83 'listeners prefix', 84 ) 85 86 self.assertEqual( 87 self.conf_get('listeners/*:7080'), 88 {"pass": "applications/app"}, 89 'listeners prefix 2', 90 ) 91 92 def test_php_change_listener(self): 93 self.conf(self.conf_basic) 94 self.conf({"*:7081": {"pass": "applications/app"}}, 'listeners') 95 96 self.assertEqual( 97 self.conf_get('listeners'), 98 {"*:7081": {"pass": "applications/app"}}, 99 'change listener', 100 ) 101 102 def test_php_add_listener(self): 103 self.conf(self.conf_basic) 104 self.conf({"pass": "applications/app"}, 'listeners/*:7082') 105 106 self.assertEqual( 107 self.conf_get('listeners'), 108 { 109 "*:7080": {"pass": "applications/app"}, 110 "*:7082": {"pass": "applications/app"}, 111 }, 112 'add listener', 113 ) 114 115 def test_php_change_application(self): 116 self.conf(self.conf_basic) 117 118 self.conf('30', 'applications/app/processes/max') 119 self.assertEqual( 120 self.conf_get('applications/app/processes/max'), 121 30, 122 'change application max', 123 ) 124 125 self.conf('"/www"', 'applications/app/root') 126 self.assertEqual( 127 self.conf_get('applications/app/root'), 128 '/www', 129 'change application root', 130 ) 131 132 def test_php_delete(self): 133 self.conf(self.conf_basic) 134 135 self.assertIn('error', self.conf_delete('applications/app')) 136 self.assertIn('success', self.conf_delete('listeners/*:7080')) 137 self.assertIn('success', self.conf_delete('applications/app')) 138 self.assertIn('error', self.conf_delete('applications/app')) 139 140 def test_php_delete_blocks(self): 141 self.conf(self.conf_basic) 142 143 self.assertIn('success', self.conf_delete('listeners')) 144 self.assertIn('success', self.conf_delete('applications')) 145 146 self.assertIn('success', self.conf(self.conf_app, 'applications')) 147 self.assertIn( 148 'success', 149 self.conf({"*:7081": {"pass": "applications/app"}}, 'listeners'), 150 'applications restore', 151 ) 152 153 154if __name__ == '__main__': 155 TestPHPBasic.main() 156