1from unit.control import TestControl 2 3 4class TestPythonBasic(TestControl): 5 prerequisites = {'modules': {'python': 'any'}} 6 7 conf_app = { 8 "app": { 9 "type": "python", 10 "processes": {"spare": 0}, 11 "path": "/app", 12 "module": "wsgi", 13 } 14 } 15 16 conf_basic = { 17 "listeners": {"*:7080": {"pass": "applications/app"}}, 18 "applications": conf_app, 19 } 20 21 def test_python_get_empty(self): 22 assert self.conf_get() == {'listeners': {}, 'applications': {}} 23 assert self.conf_get('listeners') == {} 24 assert self.conf_get('applications') == {} 25 26 def test_python_get_applications(self): 27 self.conf(self.conf_app, 'applications') 28 29 conf = self.conf_get() 30 31 assert conf['listeners'] == {}, 'listeners' 32 assert conf['applications'] == { 33 "app": { 34 "type": "python", 35 "processes": {"spare": 0}, 36 "path": "/app", 37 "module": "wsgi", 38 } 39 }, 'applications' 40 41 assert self.conf_get('applications') == { 42 "app": { 43 "type": "python", 44 "processes": {"spare": 0}, 45 "path": "/app", 46 "module": "wsgi", 47 } 48 }, 'applications prefix' 49 50 assert self.conf_get('applications/app') == { 51 "type": "python", 52 "processes": {"spare": 0}, 53 "path": "/app", 54 "module": "wsgi", 55 }, 'applications prefix 2' 56 57 assert self.conf_get('applications/app/type') == 'python', 'type' 58 assert self.conf_get('applications/app/processes/spare') == 0, 'spare' 59 60 def test_python_get_listeners(self): 61 self.conf(self.conf_basic) 62 63 assert self.conf_get()['listeners'] == { 64 "*:7080": {"pass": "applications/app"} 65 }, 'listeners' 66 67 assert self.conf_get('listeners') == { 68 "*:7080": {"pass": "applications/app"} 69 }, 'listeners prefix' 70 71 assert self.conf_get('listeners/*:7080') == { 72 "pass": "applications/app" 73 }, 'listeners prefix 2' 74 75 def test_python_change_listener(self): 76 self.conf(self.conf_basic) 77 self.conf({"*:7081": {"pass": "applications/app"}}, 'listeners') 78 79 assert self.conf_get('listeners') == { 80 "*:7081": {"pass": "applications/app"} 81 }, 'change listener' 82 83 def test_python_add_listener(self): 84 self.conf(self.conf_basic) 85 self.conf({"pass": "applications/app"}, 'listeners/*:7082') 86 87 assert self.conf_get('listeners') == { 88 "*:7080": {"pass": "applications/app"}, 89 "*:7082": {"pass": "applications/app"}, 90 }, 'add listener' 91 92 def test_python_change_application(self): 93 self.conf(self.conf_basic) 94 95 self.conf('30', 'applications/app/processes/max') 96 assert ( 97 self.conf_get('applications/app/processes/max') == 30 98 ), 'change application max' 99 100 self.conf('"/www"', 'applications/app/path') 101 assert ( 102 self.conf_get('applications/app/path') == '/www' 103 ), 'change application path' 104 105 def test_python_delete(self): 106 self.conf(self.conf_basic) 107 108 assert 'error' in self.conf_delete('applications/app') 109 assert 'success' in self.conf_delete('listeners/*:7080') 110 assert 'success' in self.conf_delete('applications/app') 111 assert 'error' in self.conf_delete('applications/app') 112 113 def test_python_delete_blocks(self): 114 self.conf(self.conf_basic) 115 116 assert 'success' in self.conf_delete('listeners') 117 assert 'success' in self.conf_delete('applications') 118 119 assert 'success' in self.conf(self.conf_app, 'applications') 120 assert 'success' in self.conf( 121 {"*:7081": {"pass": "applications/app"}}, 'listeners' 122 ), 'applications restore' 123