1from unit.applications.lang.python import ApplicationPython 2 3prerequisites = {'modules': {'python': 'any'}} 4 5client = ApplicationPython() 6 7 8def test_python_environment_name_null(): 9 client.load('environment') 10 11 assert 'error' in client.conf( 12 {"va\0r": "val1"}, 'applications/environment/environment' 13 ), 'name null' 14 15 16def test_python_environment_name_equals(): 17 client.load('environment') 18 19 assert 'error' in client.conf( 20 {"var=": "val1"}, 'applications/environment/environment' 21 ), 'name equals' 22 23 24def test_python_environment_value_null(): 25 client.load('environment') 26 27 assert 'error' in client.conf( 28 {"var": "\0val"}, 'applications/environment/environment' 29 ), 'value null' 30 31 32def test_python_environment_update(): 33 client.load('environment') 34 35 client.conf({"var": "val1"}, 'applications/environment/environment') 36 37 assert ( 38 client.get( 39 headers={ 40 'Host': 'localhost', 41 'X-Variables': 'var', 42 'Connection': 'close', 43 } 44 )['body'] 45 == 'val1' 46 ), 'set' 47 48 client.conf({"var": "val2"}, 'applications/environment/environment') 49 50 assert ( 51 client.get( 52 headers={ 53 'Host': 'localhost', 54 'X-Variables': 'var', 55 'Connection': 'close', 56 } 57 )['body'] 58 == 'val2' 59 ), 'update' 60 61 62def test_python_environment_replace(): 63 client.load('environment') 64 65 client.conf({"var1": "val1"}, 'applications/environment/environment') 66 67 assert ( 68 client.get( 69 headers={ 70 'Host': 'localhost', 71 'X-Variables': 'var1', 72 'Connection': 'close', 73 } 74 )['body'] 75 == 'val1' 76 ), 'set' 77 78 client.conf({"var2": "val2"}, 'applications/environment/environment') 79 80 assert ( 81 client.get( 82 headers={ 83 'Host': 'localhost', 84 'X-Variables': 'var1,var2', 85 'Connection': 'close', 86 } 87 )['body'] 88 == 'val2' 89 ), 'replace' 90 91 92def test_python_environment_clear(): 93 client.load('environment') 94 95 client.conf( 96 {"var1": "val1", "var2": "val2"}, 97 'applications/environment/environment', 98 ) 99 100 assert ( 101 client.get( 102 headers={ 103 'Host': 'localhost', 104 'X-Variables': 'var1,var2', 105 'Connection': 'close', 106 } 107 )['body'] 108 == 'val1,val2' 109 ), 'set' 110 111 client.conf({}, 'applications/environment/environment') 112 113 assert ( 114 client.get( 115 headers={ 116 'Host': 'localhost', 117 'X-Variables': 'var1,var2', 118 'Connection': 'close', 119 } 120 )['body'] 121 == '' 122 ), 'clear' 123 124 125def test_python_environment_replace_default(): 126 client.load('environment') 127 128 home_default = client.get( 129 headers={ 130 'Host': 'localhost', 131 'X-Variables': 'HOME', 132 'Connection': 'close', 133 } 134 )['body'] 135 136 assert len(home_default) > 1, 'get default' 137 138 client.conf({"HOME": "/"}, 'applications/environment/environment') 139 140 assert ( 141 client.get( 142 headers={ 143 'Host': 'localhost', 144 'X-Variables': 'HOME', 145 'Connection': 'close', 146 } 147 )['body'] 148 == '/' 149 ), 'replace default' 150 151 client.conf({}, 'applications/environment/environment') 152 153 assert ( 154 client.get( 155 headers={ 156 'Host': 'localhost', 157 'X-Variables': 'HOME', 158 'Connection': 'close', 159 } 160 )['body'] 161 == home_default 162 ), 'restore default' 163