1import unittest 2import unit 3 4class TestUnitPythonEnvironment(unit.TestUnitApplicationPython): 5 6 def setUpClass(): 7 unit.TestUnit().check_modules('python') 8 9 def test_python_environment_name_null(self): 10 self.load('environment') 11 12 self.assertIn('error', self.conf({ 13 "va\0r": "val1" 14 }, 'applications/environment/environment'), 'name null') 15 16 def test_python_environment_name_equals(self): 17 self.load('environment') 18 19 self.assertIn('error', self.conf({ 20 "var=": "val1" 21 }, 'applications/environment/environment'), 'name equals') 22 23 def test_python_environment_value_null(self): 24 self.load('environment') 25 26 self.assertIn('error', self.conf({ 27 "var": "\0val" 28 }, 'applications/environment/environment'), 'value null') 29 30 def test_python_environment_update(self): 31 self.load('environment') 32 33 self.conf({ 34 "var": "val1" 35 }, 'applications/environment/environment') 36 37 self.assertEqual(self.get(headers={ 38 'Host': 'localhost', 39 'X-Variables': 'var', 40 'Connection': 'close' 41 })['body'], 'val1,', 'set') 42 43 self.conf({ 44 "var": "val2" 45 }, 'applications/environment/environment') 46 47 self.assertEqual(self.get(headers={ 48 'Host': 'localhost', 49 'X-Variables': 'var', 50 'Connection': 'close' 51 })['body'], 'val2,', 'update') 52 53 def test_python_environment_replace(self): 54 self.load('environment') 55 56 self.conf({ 57 "var1": "val1" 58 }, 'applications/environment/environment') 59 60 self.assertEqual(self.get(headers={ 61 'Host': 'localhost', 62 'X-Variables': 'var1', 63 'Connection': 'close' 64 })['body'], 'val1,', 'set') 65 66 self.conf({ 67 "var2": "val2" 68 }, 'applications/environment/environment') 69 70 self.assertEqual(self.get(headers={ 71 'Host': 'localhost', 72 'X-Variables': 'var1,var2', 73 'Connection': 'close' 74 })['body'], 'val2,', 'replace') 75 76 def test_python_environment_clear(self): 77 self.load('environment') 78 79 self.conf({ 80 "var1": "val1", 81 "var2": "val2" 82 }, 'applications/environment/environment') 83 84 self.assertEqual(self.get(headers={ 85 'Host': 'localhost', 86 'X-Variables': 'var1,var2', 87 'Connection': 'close' 88 })['body'], 'val1,val2,', 'set') 89 90 self.conf({}, 'applications/environment/environment') 91 92 self.assertEqual(self.get(headers={ 93 'Host': 'localhost', 94 'X-Variables': 'var1,var2', 95 'Connection': 'close' 96 })['body'], '', 'clear') 97 98 def test_python_environment_replace_default(self): 99 self.load('environment') 100 101 pwd_default = self.get(headers={ 102 'Host': 'localhost', 103 'X-Variables': 'PWD', 104 'Connection': 'close' 105 })['body'] 106 107 self.assertGreater(len(pwd_default), 1, 'get default') 108 109 self.conf({ 110 "PWD": "new/pwd" 111 }, 'applications/environment/environment') 112 113 self.assertEqual(self.get(headers={ 114 'Host': 'localhost', 115 'X-Variables': 'PWD', 116 'Connection': 'close' 117 })['body'], 'new/pwd,', 'replace default') 118 119 self.conf({}, 'applications/environment/environment') 120 121 self.assertEqual(self.get(headers={ 122 'Host': 'localhost', 123 'X-Variables': 'PWD', 124 'Connection': 'close' 125 })['body'], pwd_default, 'restore default') 126 127if __name__ == '__main__': 128 unittest.main() 129