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 assert 'success' in 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 assert 'success' in self.conf(self.conf_basic) 77 assert 'success' in self.conf( 78 {"*:7081": {"pass": "applications/app"}}, 'listeners' 79 ) 80 81 assert self.conf_get('listeners') == { 82 "*:7081": {"pass": "applications/app"} 83 }, 'change listener' 84 85 def test_python_add_listener(self): 86 assert 'success' in self.conf(self.conf_basic) 87 assert 'success' in self.conf( 88 {"pass": "applications/app"}, 'listeners/*:7082' 89 ) 90 91 assert self.conf_get('listeners') == { 92 "*:7080": {"pass": "applications/app"}, 93 "*:7082": {"pass": "applications/app"}, 94 }, 'add listener' 95 96 def test_python_change_application(self): 97 assert 'success' in self.conf(self.conf_basic) 98 99 assert 'success' in self.conf('30', 'applications/app/processes/max') 100 assert ( 101 self.conf_get('applications/app/processes/max') == 30 102 ), 'change application max' 103 104 assert 'success' in self.conf('"/www"', 'applications/app/path') 105 assert ( 106 self.conf_get('applications/app/path') == '/www' 107 ), 'change application path' 108 109 def test_python_delete(self): 110 assert 'success' in self.conf(self.conf_basic) 111 112 assert 'error' in self.conf_delete('applications/app') 113 assert 'success' in self.conf_delete('listeners/*:7080') 114 assert 'success' in self.conf_delete('applications/app') 115 assert 'error' in self.conf_delete('applications/app') 116 117 def test_python_delete_blocks(self): 118 assert 'success' in self.conf(self.conf_basic) 119 120 assert 'success' in self.conf_delete('listeners') 121 assert 'success' in self.conf_delete('applications') 122 123 assert 'success' in self.conf(self.conf_app, 'applications') 124 assert 'success' in self.conf( 125 {"*:7081": {"pass": "applications/app"}}, 'listeners' 126 ), 'applications restore' 127