summaryrefslogtreecommitdiffhomepage
path: root/test/test_python_environment.py
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2018-05-29 15:29:01 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2018-05-29 15:29:01 +0300
commit569a907dbb55f5590d7cda1684780a1cafb0563d (patch)
tree23b081e7d2c63a8b0f0605ee121e1237ee5bf05e /test/test_python_environment.py
parentd7e6e2bd8cb81d47c9e7300937cb08ec35b6c21b (diff)
downloadunit-569a907dbb55f5590d7cda1684780a1cafb0563d.tar.gz
unit-569a907dbb55f5590d7cda1684780a1cafb0563d.tar.bz2
Tests: configuration of environment variables.
Diffstat (limited to 'test/test_python_environment.py')
-rw-r--r--test/test_python_environment.py128
1 files changed, 128 insertions, 0 deletions
diff --git a/test/test_python_environment.py b/test/test_python_environment.py
new file mode 100644
index 00000000..278f7952
--- /dev/null
+++ b/test/test_python_environment.py
@@ -0,0 +1,128 @@
+import unittest
+import unit
+
+class TestUnitPythonEnvironment(unit.TestUnitApplicationPython):
+
+ def setUpClass():
+ unit.TestUnit().check_modules('python')
+
+ def test_python_environment_name_null(self):
+ self.load('environment')
+
+ self.assertIn('error', self.conf({
+ "va\0r": "val1"
+ }, '/applications/environment/environment'), 'name null')
+
+ def test_python_environment_name_equals(self):
+ self.load('environment')
+
+ self.assertIn('error', self.conf({
+ "var=": "val1"
+ }, '/applications/environment/environment'), 'name equals')
+
+ def test_python_environment_value_null(self):
+ self.load('environment')
+
+ self.assertIn('error', self.conf({
+ "var": "\0val"
+ }, '/applications/environment/environment'), 'value null')
+
+ def test_python_environment_update(self):
+ self.load('environment')
+
+ self.conf({
+ "var": "val1"
+ }, '/applications/environment/environment')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Variables': 'var',
+ 'Connection': 'close'
+ })['body'], 'val1,', 'set')
+
+ self.conf({
+ "var": "val2"
+ }, '/applications/environment/environment')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Variables': 'var',
+ 'Connection': 'close'
+ })['body'], 'val2,', 'update')
+
+ def test_python_environment_replace(self):
+ self.load('environment')
+
+ self.conf({
+ "var1": "val1"
+ }, '/applications/environment/environment')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Variables': 'var1',
+ 'Connection': 'close'
+ })['body'], 'val1,', 'set')
+
+ self.conf({
+ "var2": "val2"
+ }, '/applications/environment/environment')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Variables': 'var1,var2',
+ 'Connection': 'close'
+ })['body'], 'val2,', 'replace')
+
+ def test_python_environment_clear(self):
+ self.load('environment')
+
+ self.conf({
+ "var1": "val1",
+ "var2": "val2"
+ }, '/applications/environment/environment')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Variables': 'var1,var2',
+ 'Connection': 'close'
+ })['body'], 'val1,val2,', 'set')
+
+ self.conf({}, '/applications/environment/environment')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Variables': 'var1,var2',
+ 'Connection': 'close'
+ })['body'], '', 'clear')
+
+ def test_python_environment_replace_default(self):
+ self.load('environment')
+
+ pwd_default = self.get(headers={
+ 'Host': 'localhost',
+ 'X-Variables': 'PWD',
+ 'Connection': 'close'
+ })['body']
+
+ self.assertGreater(len(pwd_default), 1, 'get default')
+
+ self.conf({
+ "PWD": "new/pwd"
+ }, '/applications/environment/environment')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Variables': 'PWD',
+ 'Connection': 'close'
+ })['body'], 'new/pwd,', 'replace default')
+
+ self.conf({}, '/applications/environment/environment')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Variables': 'PWD',
+ 'Connection': 'close'
+ })['body'], pwd_default, 'restore default')
+
+if __name__ == '__main__':
+ unittest.main()