Tests: used relative path for configuration.

This commit is contained in:
Andrey Zelenkov
2018-09-06 20:18:33 +03:00
parent 58d23eb5b4
commit 511a0fa760
11 changed files with 125 additions and 126 deletions

View File

@@ -13,7 +13,7 @@ class TestUnitAccessLog(unit.TestUnitApplicationPython):
def load(self, script): def load(self, script):
super().load(script) super().load(script)
self.conf('"' + self.testdir + '/access.log"', '/access_log') self.conf('"' + self.testdir + '/access.log"', 'access_log')
def search_in_log(self, pattern, name='access.log'): def search_in_log(self, pattern, name='access.log'):
with open(self.testdir + '/' + name, 'r') as f: with open(self.testdir + '/' + name, 'r') as f:
@@ -85,7 +85,7 @@ Connection: close
"[::1]:7080": { "[::1]:7080": {
"application": "empty" "application": "empty"
} }
}, '/listeners') }, 'listeners')
self.get(sock_type='ipv6') self.get(sock_type='ipv6')
@@ -106,7 +106,7 @@ Connection: close
"unix:" + addr: { "unix:" + addr: {
"application": "empty" "application": "empty"
} }
}, '/listeners') }, 'listeners')
self.get(sock_type='unix', addr=addr) self.get(sock_type='unix', addr=addr)
@@ -240,7 +240,7 @@ Connection: close
def test_access_log_delete(self): def test_access_log_delete(self):
self.load('empty') self.load('empty')
self.conf_delete('/access_log') self.conf_delete('access_log')
self.get(url='/delete') self.get(url='/delete')
@@ -255,7 +255,7 @@ Connection: close
self.get() self.get()
self.conf('"' + self.testdir + '/new.log"', '/access_log') self.conf('"' + self.testdir + '/new.log"', 'access_log')
self.get() self.get()

View File

@@ -22,9 +22,9 @@ class TestUnitConfiguration(unit.TestUnitControl):
"module": "wsgi" "module": "wsgi"
} }
} }
""", '/applications'), 'unicode') """, 'applications'), 'unicode')
self.assertDictEqual(self.conf_get('/applications'), { self.assertDictEqual(self.conf_get('applications'), {
"app": { "app": {
"type": "python", "type": "python",
"processes": { "spare": 0 }, "processes": { "spare": 0 },
@@ -41,9 +41,9 @@ class TestUnitConfiguration(unit.TestUnitControl):
"path": "/app", "path": "/app",
"module": "wsgi" "module": "wsgi"
} }
}, '/applications'), 'unicode 2') }, 'applications'), 'unicode 2')
self.assertIn('приложение', self.conf_get('/applications'), self.assertIn('приложение', self.conf_get('applications'),
'unicode 2 get') 'unicode 2 get')
def test_json_unicode_number(self): def test_json_unicode_number(self):
@@ -56,13 +56,13 @@ class TestUnitConfiguration(unit.TestUnitControl):
"module": "wsgi" "module": "wsgi"
} }
} }
""", '/applications'), 'unicode number') """, 'applications'), 'unicode number')
def test_applications_open_brace(self): def test_applications_open_brace(self):
self.assertIn('error', self.conf('{', '/applications'), 'open brace') self.assertIn('error', self.conf('{', 'applications'), 'open brace')
def test_applications_string(self): def test_applications_string(self):
self.assertIn('error', self.conf('"{}"', '/applications'), 'string') self.assertIn('error', self.conf('"{}"', 'applications'), 'string')
def test_applications_type_only(self): def test_applications_type_only(self):
self.skip_alerts.extend([ self.skip_alerts.extend([
@@ -75,7 +75,7 @@ class TestUnitConfiguration(unit.TestUnitControl):
"app": { "app": {
"type": "python" "type": "python"
} }
}, '/applications'), 'type only') }, 'applications'), 'type only')
def test_applications_miss_quote(self): def test_applications_miss_quote(self):
self.assertIn('error', self.conf(""" self.assertIn('error', self.conf("""
@@ -87,7 +87,7 @@ class TestUnitConfiguration(unit.TestUnitControl):
"module": "wsgi" "module": "wsgi"
} }
} }
""", '/applications'), 'miss quote') """, 'applications'), 'miss quote')
def test_applications_miss_colon(self): def test_applications_miss_colon(self):
self.assertIn('error', self.conf(""" self.assertIn('error', self.conf("""
@@ -99,7 +99,7 @@ class TestUnitConfiguration(unit.TestUnitControl):
"module": "wsgi" "module": "wsgi"
} }
} }
""", '/applications'), 'miss colon') """, 'applications'), 'miss colon')
def test_applications_miss_comma(self): def test_applications_miss_comma(self):
self.assertIn('error', self.conf(""" self.assertIn('error', self.conf("""
@@ -111,10 +111,10 @@ class TestUnitConfiguration(unit.TestUnitControl):
"module": "wsgi" "module": "wsgi"
} }
} }
""", '/applications'), 'miss comma') """, 'applications'), 'miss comma')
def test_applications_skip_spaces(self): def test_applications_skip_spaces(self):
self.assertIn('success', self.conf(b'{ \n\r\t}', '/applications'), self.assertIn('success', self.conf(b'{ \n\r\t}', 'applications'),
'skip spaces') 'skip spaces')
def test_applications_relative_path(self): def test_applications_relative_path(self):
@@ -125,7 +125,7 @@ class TestUnitConfiguration(unit.TestUnitControl):
"path": "../app", "path": "../app",
"module": "wsgi" "module": "wsgi"
} }
}, '/applications'), 'relative path') }, 'applications'), 'relative path')
@unittest.expectedFailure @unittest.expectedFailure
def test_listeners_empty(self): def test_listeners_empty(self):
@@ -136,12 +136,12 @@ class TestUnitConfiguration(unit.TestUnitControl):
r'process \d+ exited on signal' r'process \d+ exited on signal'
]) ])
self.assertIn('error', self.conf({"*:7080":{}}, '/listeners'), self.assertIn('error', self.conf({"*:7080":{}}, 'listeners'),
'listener empty') 'listener empty')
def test_listeners_no_app(self): def test_listeners_no_app(self):
self.assertIn('error', self.conf({"*:7080":{"application":"app"}}, self.assertIn('error', self.conf({"*:7080":{"application":"app"}},
'/listeners'), 'listeners no app') 'listeners'), 'listeners no app')
def test_listeners_wildcard(self): def test_listeners_wildcard(self):
self.assertIn('success', self.conf({ self.assertIn('success', self.conf({

View File

@@ -110,13 +110,13 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo):
self.load('command_line_arguments') self.load('command_line_arguments')
self.assertIn('error', self.conf(''"a b c", self.assertIn('error', self.conf(''"a b c",
'/applications/command_line_arguments/arguments'), 'arguments type') 'applications/command_line_arguments/arguments'), 'arguments type')
def test_go_application_command_line_arguments_0(self): def test_go_application_command_line_arguments_0(self):
self.load('command_line_arguments') self.load('command_line_arguments')
self.assertEqual(self.get()['headers']['X-Arg-0'], self.assertEqual(self.get()['headers']['X-Arg-0'],
self.conf_get('/applications/command_line_arguments/executable'), self.conf_get('applications/command_line_arguments/executable'),
'argument 0') 'argument 0')
def test_go_application_command_line_arguments(self): def test_go_application_command_line_arguments(self):
@@ -127,7 +127,7 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo):
arg3 = '--debug' arg3 = '--debug'
self.conf('["' + arg1 + '", "' + arg2 + '", "' + arg3 + '"]', self.conf('["' + arg1 + '", "' + arg2 + '", "' + arg3 + '"]',
'/applications/command_line_arguments/arguments') 'applications/command_line_arguments/arguments')
self.assertEqual(self.get()['body'], arg1 + ',' + arg2 + ',' + arg3, self.assertEqual(self.get()['body'], arg1 + ',' + arg2 + ',' + arg3,
'arguments') 'arguments')
@@ -135,7 +135,7 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo):
def test_go_application_command_line_arguments_change(self): def test_go_application_command_line_arguments_change(self):
self.load('command_line_arguments') self.load('command_line_arguments')
args_path = '/applications/command_line_arguments/arguments' args_path = 'applications/command_line_arguments/arguments'
self.conf('["0", "a", "$", ""]', args_path) self.conf('["0", "a", "$", ""]', args_path)

View File

@@ -124,7 +124,7 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
self.assertNotEqual(self.get()['headers']['X-Precision'], '4', self.assertNotEqual(self.get()['headers']['X-Precision'], '4',
'ini value default') 'ini value default')
self.conf({"file": "php.ini"}, '/applications/ini_precision/options') self.conf({"file": "php.ini"}, 'applications/ini_precision/options')
self.assertEqual(self.get()['headers']['X-File'], self.assertEqual(self.get()['headers']['X-File'],
self.current_dir + '/php/ini_precision/php.ini', 'ini file') self.current_dir + '/php/ini_precision/php.ini', 'ini file')
@@ -137,7 +137,7 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
self.assertIn('error', self.conf({ self.assertIn('error', self.conf({
"user": { "precision": "4" }, "user": { "precision": "4" },
"admin": { "precision": "5" } "admin": { "precision": "5" }
}, '/applications/ini_precision/options'), 'ini admin user') }, 'applications/ini_precision/options'), 'ini admin user')
def test_php_application_ini_admin(self): def test_php_application_ini_admin(self):
self.load('ini_precision') self.load('ini_precision')
@@ -145,7 +145,7 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
self.conf({ self.conf({
"file": "php.ini", "file": "php.ini",
"admin": { "precision": "5" } "admin": { "precision": "5" }
}, '/applications/ini_precision/options') }, 'applications/ini_precision/options')
self.assertEqual(self.get()['headers']['X-Precision'], '5', self.assertEqual(self.get()['headers']['X-Precision'], '5',
'ini value admin') 'ini value admin')
@@ -156,7 +156,7 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
self.conf({ self.conf({
"file": "php.ini", "file": "php.ini",
"user": { "precision": "5" } "user": { "precision": "5" }
}, '/applications/ini_precision/options') }, 'applications/ini_precision/options')
self.assertEqual(self.get()['headers']['X-Precision'], '5', self.assertEqual(self.get()['headers']['X-Precision'], '5',
'ini value user') 'ini value user')
@@ -164,13 +164,13 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
def test_php_application_ini_user_2(self): def test_php_application_ini_user_2(self):
self.load('ini_precision') self.load('ini_precision')
self.conf({"file": "php.ini"}, '/applications/ini_precision/options') self.conf({"file": "php.ini"}, 'applications/ini_precision/options')
self.assertEqual(self.get()['headers']['X-Precision'], '4', self.assertEqual(self.get()['headers']['X-Precision'], '4',
'ini user file') 'ini user file')
self.conf({ "precision": "5" }, self.conf({ "precision": "5" },
'/applications/ini_precision/options/user') 'applications/ini_precision/options/user')
self.assertEqual(self.get()['headers']['X-Precision'], '5', self.assertEqual(self.get()['headers']['X-Precision'], '5',
'ini value user') 'ini value user')
@@ -179,7 +179,7 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
self.load('ini_precision') self.load('ini_precision')
self.conf({"admin": { "precision": "5" }}, self.conf({"admin": { "precision": "5" }},
'/applications/ini_precision/options') 'applications/ini_precision/options')
self.assertEqual(self.get(url='/?precision=6')['headers']['X-Precision'], self.assertEqual(self.get(url='/?precision=6')['headers']['X-Precision'],
'5', 'ini set admin') '5', 'ini set admin')
@@ -188,7 +188,7 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
self.load('ini_precision') self.load('ini_precision')
self.conf({"user": { "precision": "5" }}, self.conf({"user": { "precision": "5" }},
'/applications/ini_precision/options') 'applications/ini_precision/options')
self.assertEqual(self.get(url='/?precision=6')['headers']['X-Precision'], self.assertEqual(self.get(url='/?precision=6')['headers']['X-Precision'],
'6', 'ini set user') '6', 'ini set user')
@@ -197,7 +197,7 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
self.load('ini_precision') self.load('ini_precision')
self.conf({"user": { "precision": "5" }}, self.conf({"user": { "precision": "5" }},
'/applications/ini_precision/options') 'applications/ini_precision/options')
self.assertEqual(self.get()['headers']['X-Precision'], '5', 'ini value') self.assertEqual(self.get()['headers']['X-Precision'], '5', 'ini value')

View File

@@ -25,7 +25,7 @@ class TestUnitPHPBasic(unit.TestUnitControl):
} }
def test_php_get_applications(self): def test_php_get_applications(self):
self.conf(self.conf_app, '/applications') self.conf(self.conf_app, 'applications')
conf = self.conf_get() conf = self.conf_get()
@@ -42,9 +42,9 @@ class TestUnitPHPBasic(unit.TestUnitControl):
'applications') 'applications')
def test_php_get_applications_prefix(self): def test_php_get_applications_prefix(self):
self.conf(self.conf_app, '/applications') self.conf(self.conf_app, 'applications')
self.assertEqual(self.conf_get('/applications'), self.assertEqual(self.conf_get('applications'),
{ {
"app": { "app": {
"type": "php", "type": "php",
@@ -56,9 +56,9 @@ class TestUnitPHPBasic(unit.TestUnitControl):
'applications prefix') 'applications prefix')
def test_php_get_applications_prefix_2(self): def test_php_get_applications_prefix_2(self):
self.conf(self.conf_app, '/applications') self.conf(self.conf_app, 'applications')
self.assertEqual(self.conf_get('/applications/app'), self.assertEqual(self.conf_get('applications/app'),
{ {
"type": "php", "type": "php",
"processes": { "spare": 0 }, "processes": { "spare": 0 },
@@ -68,11 +68,11 @@ class TestUnitPHPBasic(unit.TestUnitControl):
'applications prefix 2') 'applications prefix 2')
def test_php_get_applications_prefix_3(self): def test_php_get_applications_prefix_3(self):
self.conf(self.conf_app, '/applications') self.conf(self.conf_app, 'applications')
self.assertEqual(self.conf_get('/applications/app/type'), 'php', self.assertEqual(self.conf_get('applications/app/type'), 'php',
'type') 'type')
self.assertEqual(self.conf_get('/applications/app/processes/spare'), 0, self.assertEqual(self.conf_get('applications/app/processes/spare'), 0,
'spare processes') 'spare processes')
def test_php_get_listeners(self): def test_php_get_listeners(self):
@@ -84,27 +84,27 @@ class TestUnitPHPBasic(unit.TestUnitControl):
def test_php_get_listeners_prefix(self): def test_php_get_listeners_prefix(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.assertEqual(self.conf_get('/listeners'), self.assertEqual(self.conf_get('listeners'),
{"*:7080":{"application":"app"}}, 'listeners prefix') {"*:7080":{"application":"app"}}, 'listeners prefix')
def test_php_get_listeners_prefix_2(self): def test_php_get_listeners_prefix_2(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.assertEqual(self.conf_get('/listeners/*:7080'), self.assertEqual(self.conf_get('listeners/*:7080'),
{"application":"app"}, 'listeners prefix 2') {"application":"app"}, 'listeners prefix 2')
def test_php_change_listener(self): def test_php_change_listener(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.conf({"*:7081":{"application":"app"}}, '/listeners') self.conf({"*:7081":{"application":"app"}}, 'listeners')
self.assertEqual(self.conf_get('/listeners'), self.assertEqual(self.conf_get('listeners'),
{"*:7081": {"application":"app"}}, 'change listener') {"*:7081": {"application":"app"}}, 'change listener')
def test_php_add_listener(self): def test_php_add_listener(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.conf({"application":"app"}, '/listeners/*:7082') self.conf({"application":"app"}, 'listeners/*:7082')
self.assertEqual(self.conf_get('/listeners'), self.assertEqual(self.conf_get('listeners'),
{ {
"*:7080": { "*:7080": {
"application": "app" "application": "app"
@@ -118,24 +118,24 @@ class TestUnitPHPBasic(unit.TestUnitControl):
def test_php_change_application(self): def test_php_change_application(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.conf('30', '/applications/app/processes/max') self.conf('30', 'applications/app/processes/max')
self.assertEqual(self.conf_get('/applications/app/processes/max'), 30, self.assertEqual(self.conf_get('applications/app/processes/max'), 30,
'change application max') 'change application max')
self.conf('"/www"', '/applications/app/root') self.conf('"/www"', 'applications/app/root')
self.assertEqual(self.conf_get('/applications/app/root'), '/www', self.assertEqual(self.conf_get('applications/app/root'), '/www',
'change application root') 'change application root')
def test_php_delete(self): def test_php_delete(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.assertIn('error', self.conf_delete('/applications/app'), self.assertIn('error', self.conf_delete('applications/app'),
'delete app before listener') 'delete app before listener')
self.assertIn('success', self.conf_delete('/listeners/*:7080'), self.assertIn('success', self.conf_delete('listeners/*:7080'),
'delete listener') 'delete listener')
self.assertIn('success', self.conf_delete('/applications/app'), self.assertIn('success', self.conf_delete('applications/app'),
'delete app after listener') 'delete app after listener')
self.assertIn('error', self.conf_delete('/applications/app'), self.assertIn('error', self.conf_delete('applications/app'),
'delete app again') 'delete app again')
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -131,7 +131,7 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
self.assertIn('success', self.conf({ self.assertIn('success', self.conf({
"spare": i % 4, "spare": i % 4,
"max": (i % 4) + 1 "max": (i % 4) + 1
}, '/applications/mirror/processes'), 'reconfigure') }, 'applications/mirror/processes'), 'reconfigure')
socks.append(sock) socks.append(sock)
@@ -146,7 +146,7 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
self.assertIn('success', self.conf({ self.assertIn('success', self.conf({
"spare": i % 4, "spare": i % 4,
"max": (i % 4) + 1 "max": (i % 4) + 1
}, '/applications/mirror/processes'), 'reconfigure 2') }, 'applications/mirror/processes'), 'reconfigure 2')
for i in range(conns): for i in range(conns):
resp = self.post(headers={ resp = self.post(headers={
@@ -159,7 +159,7 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
self.assertIn('success', self.conf({ self.assertIn('success', self.conf({
"spare": i % 4, "spare": i % 4,
"max": (i % 4) + 1 "max": (i % 4) + 1
}, '/applications/mirror/processes'), 'reconfigure 3') }, 'applications/mirror/processes'), 'reconfigure 3')
def test_python_keepalive_reconfigure_2(self): def test_python_keepalive_reconfigure_2(self):
self.skip_alerts.append(r'sendmsg.+failed') self.skip_alerts.append(r'sendmsg.+failed')

View File

@@ -29,13 +29,13 @@ class TestUnitPythonBasic(unit.TestUnitControl):
{'listeners': {}, 'applications': {}}, 'empty') {'listeners': {}, 'applications': {}}, 'empty')
def test_python_get_prefix_listeners(self): def test_python_get_prefix_listeners(self):
self.assertEqual(self.conf_get('/listeners'), {}, 'listeners prefix') self.assertEqual(self.conf_get('listeners'), {}, 'listeners prefix')
def test_python_get_prefix_applications(self): def test_python_get_prefix_applications(self):
self.assertEqual(self.conf_get('/applications'), {}, 'applications prefix') self.assertEqual(self.conf_get('applications'), {}, 'applications prefix')
def test_python_get_applications(self): def test_python_get_applications(self):
self.conf(self.conf_app, '/applications') self.conf(self.conf_app, 'applications')
conf = self.conf_get() conf = self.conf_get()
@@ -52,9 +52,9 @@ class TestUnitPythonBasic(unit.TestUnitControl):
'applications') 'applications')
def test_python_get_applications_prefix(self): def test_python_get_applications_prefix(self):
self.conf(self.conf_app, '/applications') self.conf(self.conf_app, 'applications')
self.assertEqual(self.conf_get('/applications'), self.assertEqual(self.conf_get('applications'),
{ {
"app": { "app": {
"type": "python", "type": "python",
@@ -66,9 +66,9 @@ class TestUnitPythonBasic(unit.TestUnitControl):
'applications prefix') 'applications prefix')
def test_python_get_applications_prefix_2(self): def test_python_get_applications_prefix_2(self):
self.conf(self.conf_app, '/applications') self.conf(self.conf_app, 'applications')
self.assertEqual(self.conf_get('/applications/app'), self.assertEqual(self.conf_get('applications/app'),
{ {
"type": "python", "type": "python",
"processes": { "spare": 0 }, "processes": { "spare": 0 },
@@ -78,11 +78,11 @@ class TestUnitPythonBasic(unit.TestUnitControl):
'applications prefix 2') 'applications prefix 2')
def test_python_get_applications_prefix_3(self): def test_python_get_applications_prefix_3(self):
self.conf(self.conf_app, '/applications') self.conf(self.conf_app, 'applications')
self.assertEqual(self.conf_get('/applications/app/type'), 'python', self.assertEqual(self.conf_get('applications/app/type'), 'python',
'type') 'type')
self.assertEqual(self.conf_get('/applications/app/processes/spare'), 0, self.assertEqual(self.conf_get('applications/app/processes/spare'), 0,
'spare') 'spare')
def test_python_get_listeners(self): def test_python_get_listeners(self):
@@ -94,27 +94,27 @@ class TestUnitPythonBasic(unit.TestUnitControl):
def test_python_get_listeners_prefix(self): def test_python_get_listeners_prefix(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.assertEqual(self.conf_get('/listeners'), self.assertEqual(self.conf_get('listeners'),
{"*:7080":{"application":"app"}}, 'listeners prefix') {"*:7080":{"application":"app"}}, 'listeners prefix')
def test_python_get_listeners_prefix_2(self): def test_python_get_listeners_prefix_2(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.assertEqual(self.conf_get('/listeners/*:7080'), self.assertEqual(self.conf_get('listeners/*:7080'),
{"application":"app"}, 'listeners prefix 2') {"application":"app"}, 'listeners prefix 2')
def test_python_change_listener(self): def test_python_change_listener(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.conf({"*:7081":{"application":"app"}}, '/listeners') self.conf({"*:7081":{"application":"app"}}, 'listeners')
self.assertEqual(self.conf_get('/listeners'), self.assertEqual(self.conf_get('listeners'),
{"*:7081": {"application":"app"}}, 'change listener') {"*:7081": {"application":"app"}}, 'change listener')
def test_python_add_listener(self): def test_python_add_listener(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.conf({"application":"app"}, '/listeners/*:7082') self.conf({"application":"app"}, 'listeners/*:7082')
self.assertEqual(self.conf_get('/listeners'), self.assertEqual(self.conf_get('listeners'),
{ {
"*:7080": { "*:7080": {
"application": "app" "application": "app"
@@ -128,24 +128,24 @@ class TestUnitPythonBasic(unit.TestUnitControl):
def test_python_change_application(self): def test_python_change_application(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.conf('30', '/applications/app/processes/max') self.conf('30', 'applications/app/processes/max')
self.assertEqual(self.conf_get('/applications/app/processes/max'), 30, self.assertEqual(self.conf_get('applications/app/processes/max'), 30,
'change application max') 'change application max')
self.conf('"/www"', '/applications/app/path') self.conf('"/www"', 'applications/app/path')
self.assertEqual(self.conf_get('/applications/app/path'), '/www', self.assertEqual(self.conf_get('applications/app/path'), '/www',
'change application path') 'change application path')
def test_python_delete(self): def test_python_delete(self):
self.conf(self.conf_basic) self.conf(self.conf_basic)
self.assertIn('error', self.conf_delete('/applications/app'), self.assertIn('error', self.conf_delete('applications/app'),
'delete app before listener') 'delete app before listener')
self.assertIn('success', self.conf_delete('/listeners/*:7080'), self.assertIn('success', self.conf_delete('listeners/*:7080'),
'delete listener') 'delete listener')
self.assertIn('success', self.conf_delete('/applications/app'), self.assertIn('success', self.conf_delete('applications/app'),
'delete app after listener') 'delete app after listener')
self.assertIn('error', self.conf_delete('/applications/app'), self.assertIn('error', self.conf_delete('applications/app'),
'delete app again') 'delete app again')
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -11,28 +11,28 @@ class TestUnitPythonEnvironment(unit.TestUnitApplicationPython):
self.assertIn('error', self.conf({ self.assertIn('error', self.conf({
"va\0r": "val1" "va\0r": "val1"
}, '/applications/environment/environment'), 'name null') }, 'applications/environment/environment'), 'name null')
def test_python_environment_name_equals(self): def test_python_environment_name_equals(self):
self.load('environment') self.load('environment')
self.assertIn('error', self.conf({ self.assertIn('error', self.conf({
"var=": "val1" "var=": "val1"
}, '/applications/environment/environment'), 'name equals') }, 'applications/environment/environment'), 'name equals')
def test_python_environment_value_null(self): def test_python_environment_value_null(self):
self.load('environment') self.load('environment')
self.assertIn('error', self.conf({ self.assertIn('error', self.conf({
"var": "\0val" "var": "\0val"
}, '/applications/environment/environment'), 'value null') }, 'applications/environment/environment'), 'value null')
def test_python_environment_update(self): def test_python_environment_update(self):
self.load('environment') self.load('environment')
self.conf({ self.conf({
"var": "val1" "var": "val1"
}, '/applications/environment/environment') }, 'applications/environment/environment')
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
@@ -42,7 +42,7 @@ class TestUnitPythonEnvironment(unit.TestUnitApplicationPython):
self.conf({ self.conf({
"var": "val2" "var": "val2"
}, '/applications/environment/environment') }, 'applications/environment/environment')
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
@@ -55,7 +55,7 @@ class TestUnitPythonEnvironment(unit.TestUnitApplicationPython):
self.conf({ self.conf({
"var1": "val1" "var1": "val1"
}, '/applications/environment/environment') }, 'applications/environment/environment')
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
@@ -65,7 +65,7 @@ class TestUnitPythonEnvironment(unit.TestUnitApplicationPython):
self.conf({ self.conf({
"var2": "val2" "var2": "val2"
}, '/applications/environment/environment') }, 'applications/environment/environment')
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
@@ -79,7 +79,7 @@ class TestUnitPythonEnvironment(unit.TestUnitApplicationPython):
self.conf({ self.conf({
"var1": "val1", "var1": "val1",
"var2": "val2" "var2": "val2"
}, '/applications/environment/environment') }, 'applications/environment/environment')
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
@@ -87,7 +87,7 @@ class TestUnitPythonEnvironment(unit.TestUnitApplicationPython):
'Connection': 'close' 'Connection': 'close'
})['body'], 'val1,val2,', 'set') })['body'], 'val1,val2,', 'set')
self.conf({}, '/applications/environment/environment') self.conf({}, 'applications/environment/environment')
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
@@ -108,7 +108,7 @@ class TestUnitPythonEnvironment(unit.TestUnitApplicationPython):
self.conf({ self.conf({
"PWD": "new/pwd" "PWD": "new/pwd"
}, '/applications/environment/environment') }, 'applications/environment/environment')
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
@@ -116,7 +116,7 @@ class TestUnitPythonEnvironment(unit.TestUnitApplicationPython):
'Connection': 'close' 'Connection': 'close'
})['body'], 'new/pwd,', 'replace default') })['body'], 'new/pwd,', 'replace default')
self.conf({}, '/applications/environment/environment') self.conf({}, 'applications/environment/environment')
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',

View File

@@ -27,7 +27,7 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
self.load('empty', self.app_name) self.load('empty', self.app_name)
def test_python_processes_access(self): def test_python_processes_access(self):
self.conf('1', '/applications/' + self.app_name + '/processes') self.conf('1', 'applications/' + self.app_name + '/processes')
self.assertIn('error', self.conf_get('/applications/' + self.app_name + self.assertIn('error', self.conf_get('/applications/' + self.app_name +
'/processes/max'), 'max no access') '/processes/max'), 'max no access')
@@ -39,22 +39,22 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
def test_python_processes_spare_negative(self): def test_python_processes_spare_negative(self):
self.assertIn('error', self.conf({ self.assertIn('error', self.conf({
"spare": -1 "spare": -1
}, '/applications/' + self.app_name + '/processes'), 'negative spare') }, 'applications/' + self.app_name + '/processes'), 'negative spare')
def test_python_processes_max_negative(self): def test_python_processes_max_negative(self):
self.assertIn('error', self.conf({ self.assertIn('error', self.conf({
"max": -1 "max": -1
}, '/applications/' + self.app_name + '/processes'), 'negative max') }, 'applications/' + self.app_name + '/processes'), 'negative max')
def test_python_processes_idle_timeout_negative(self): def test_python_processes_idle_timeout_negative(self):
self.assertIn('error', self.conf({ self.assertIn('error', self.conf({
"idle_timeout": -1 "idle_timeout": -1
}, '/applications/' + self.app_name + '/processes'), }, 'applications/' + self.app_name + '/processes'),
'negative idle_timeout') 'negative idle_timeout')
def test_python_processes_spare_gt_max_default(self): def test_python_processes_spare_gt_max_default(self):
self.assertIn('error', self.conf({"spare": 2}, self.assertIn('error', self.conf({"spare": 2},
'/applications/' + self.app_name + '/processes'), 'applications/' + self.app_name + '/processes'),
'spare greater than max default') 'spare greater than max default')
def test_python_processes_spare_gt_max(self): def test_python_processes_spare_gt_max(self):
@@ -70,20 +70,20 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
"spare": 0, "spare": 0,
"max": 0, "max": 0,
"idle_timeout": 1 "idle_timeout": 1
}, '/applications/' + self.app_name + '/processes'), 'max 0') }, 'applications/' + self.app_name + '/processes'), 'max 0')
def test_python_processes_idle_timeout_zero(self): def test_python_processes_idle_timeout_zero(self):
self.conf({ self.conf({
"spare": 0, "spare": 0,
"max": 2, "max": 2,
"idle_timeout": 0 "idle_timeout": 0
}, '/applications/' + self.app_name + '/processes') }, 'applications/' + self.app_name + '/processes')
self.get() self.get()
self.assertEqual(len(self.pids_for_process()), 0, 'idle timeout 0') self.assertEqual(len(self.pids_for_process()), 0, 'idle timeout 0')
def test_python_prefork(self): def test_python_prefork(self):
self.conf('2', '/applications/' + self.app_name + '/processes') self.conf('2', 'applications/' + self.app_name + '/processes')
pids = self.pids_for_process() pids = self.pids_for_process()
self.assertEqual(len(pids), 2, 'prefork 2') self.assertEqual(len(pids), 2, 'prefork 2')
@@ -91,7 +91,7 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
self.get() self.get()
self.assertSetEqual(self.pids_for_process(), pids, 'prefork still 2') self.assertSetEqual(self.pids_for_process(), pids, 'prefork still 2')
self.conf('4', '/applications/' + self.app_name + '/processes') self.conf('4', 'applications/' + self.app_name + '/processes')
pids = self.pids_for_process() pids = self.pids_for_process()
self.assertEqual(len(pids), 4, 'prefork 4') self.assertEqual(len(pids), 4, 'prefork 4')
@@ -103,11 +103,11 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
@unittest.expectedFailure @unittest.expectedFailure
def test_python_prefork_same_processes(self): def test_python_prefork_same_processes(self):
self.conf('2', '/applications/' + self.app_name + '/processes') self.conf('2', 'applications/' + self.app_name + '/processes')
pids = self.pids_for_process() pids = self.pids_for_process()
self.conf('4', '/applications/' + self.app_name + '/processes') self.conf('4', 'applications/' + self.app_name + '/processes')
pids_new = self.pids_for_process() pids_new = self.pids_for_process()
@@ -118,7 +118,7 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
"spare": 0, "spare": 0,
"max": 8, "max": 8,
"idle_timeout": 1 "idle_timeout": 1
}, '/applications/' + self.app_name + '/processes') }, 'applications/' + self.app_name + '/processes')
self.assertEqual(len(self.pids_for_process()), 0, 'on-demand 0') self.assertEqual(len(self.pids_for_process()), 0, 'on-demand 0')
@@ -140,7 +140,7 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
"spare": 2, "spare": 2,
"max": 8, "max": 8,
"idle_timeout": 1 "idle_timeout": 1
}, '/applications/' + self.app_name + '/processes') }, 'applications/' + self.app_name + '/processes')
pids = self.pids_for_process() pids = self.pids_for_process()
self.assertEqual(len(pids), 2, 'updown 2') self.assertEqual(len(pids), 2, 'updown 2')
@@ -170,7 +170,7 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
"spare": 2, "spare": 2,
"max": 6, "max": 6,
"idle_timeout": 1 "idle_timeout": 1
}, '/applications/' + self.app_name + '/processes') }, 'applications/' + self.app_name + '/processes')
pids = self.pids_for_process() pids = self.pids_for_process()
self.assertEqual(len(pids), 2, 'reconf 2') self.assertEqual(len(pids), 2, 'reconf 2')
@@ -180,7 +180,7 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
self.assertEqual(len(pids_new), 3, 'reconf 3') self.assertEqual(len(pids_new), 3, 'reconf 3')
self.assertTrue(pids.issubset(pids_new), 'reconf 3 only 1 new') self.assertTrue(pids.issubset(pids_new), 'reconf 3 only 1 new')
self.conf('6', '/applications/' + self.app_name + '/processes/spare') self.conf('6', 'applications/' + self.app_name + '/processes/spare')
pids = self.pids_for_process() pids = self.pids_for_process()
self.assertEqual(len(pids), 6, 'reconf 6') self.assertEqual(len(pids), 6, 'reconf 6')
@@ -195,7 +195,7 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
"spare": 0, "spare": 0,
"max": 6, "max": 6,
"idle_timeout": 2 "idle_timeout": 2
}, '/applications/' + self.app_name + '/processes') }, 'applications/' + self.app_name + '/processes')
self.get() self.get()
pids = self.pids_for_process() pids = self.pids_for_process()
@@ -221,7 +221,7 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython):
"spare": 0, "spare": 0,
"max": 6, "max": 6,
"idle_timeout": 2 "idle_timeout": 2
}, '/applications/' + self.app_name + '/processes') }, 'applications/' + self.app_name + '/processes')
(resp, sock) = self.get(headers={ (resp, sock) = self.get(headers={
'Host': 'localhost', 'Host': 'localhost',

View File

@@ -11,7 +11,7 @@ class TestUnitSettings(unit.TestUnitApplicationPython):
def test_settings_header_read_timeout(self): def test_settings_header_read_timeout(self):
self.load('empty') self.load('empty')
self.conf({'http': { 'header_read_timeout': 2 }}, '/settings') self.conf({'http': { 'header_read_timeout': 2 }}, 'settings')
(resp, sock) = self.http(b"""GET / HTTP/1.1 (resp, sock) = self.http(b"""GET / HTTP/1.1
""", start=True, raw=True) """, start=True, raw=True)
@@ -29,7 +29,7 @@ Connection: close
def test_settings_header_read_timeout_update(self): def test_settings_header_read_timeout_update(self):
self.load('empty') self.load('empty')
self.conf({'http': { 'header_read_timeout': 4 }}, '/settings') self.conf({'http': { 'header_read_timeout': 4 }}, 'settings')
(resp, sock) = self.http(b"""GET / HTTP/1.1 (resp, sock) = self.http(b"""GET / HTTP/1.1
""", start=True, raw=True, no_recv=True) """, start=True, raw=True, no_recv=True)
@@ -56,7 +56,7 @@ Connection: close
def test_settings_body_read_timeout(self): def test_settings_body_read_timeout(self):
self.load('empty') self.load('empty')
self.conf({'http': { 'body_read_timeout': 2 }}, '/settings') self.conf({'http': { 'body_read_timeout': 2 }}, 'settings')
(resp, sock) = self.http(b"""POST / HTTP/1.1 (resp, sock) = self.http(b"""POST / HTTP/1.1
Host: localhost Host: localhost
@@ -74,7 +74,7 @@ Connection: close
def test_settings_body_read_timeout_update(self): def test_settings_body_read_timeout_update(self):
self.load('empty') self.load('empty')
self.conf({'http': { 'body_read_timeout': 4 }}, '/settings') self.conf({'http': { 'body_read_timeout': 4 }}, 'settings')
(resp, sock) = self.http(b"""POST / HTTP/1.1 (resp, sock) = self.http(b"""POST / HTTP/1.1
Host: localhost Host: localhost
@@ -102,11 +102,11 @@ Connection: close
data_len = 1048576 data_len = 1048576
self.conf({'http': { 'send_timeout': 1 }}, '/settings') self.conf({'http': { 'send_timeout': 1 }}, 'settings')
addr = self.testdir + '/sock' addr = self.testdir + '/sock'
self.conf({"unix:" + addr: {'application': 'mirror'}}, '/listeners') self.conf({"unix:" + addr: {'application': 'mirror'}}, 'listeners')
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(addr) sock.connect(addr)
@@ -134,7 +134,7 @@ Content-Length: %d
def test_settings_idle_timeout(self): def test_settings_idle_timeout(self):
self.load('empty') self.load('empty')
self.conf({'http': { 'idle_timeout': 2 }}, '/settings') self.conf({'http': { 'idle_timeout': 2 }}, 'settings')
(resp, sock) = self.get(headers={ (resp, sock) = self.get(headers={
'Connection': 'keep-alive', 'Connection': 'keep-alive',
@@ -153,7 +153,7 @@ Content-Length: %d
def test_settings_max_body_size(self): def test_settings_max_body_size(self):
self.load('empty') self.load('empty')
self.conf({'http': { 'max_body_size': 5 }}, '/settings') self.conf({'http': { 'max_body_size': 5 }}, 'settings')
self.assertEqual(self.post(body='01234')['status'], 200, 'status size') self.assertEqual(self.post(body='01234')['status'], 200, 'status size')
self.assertEqual(self.post(body='012345')['status'], 413, self.assertEqual(self.post(body='012345')['status'], 413,
@@ -162,8 +162,7 @@ Content-Length: %d
@unittest.expectedFailure @unittest.expectedFailure
def test_settings_negative_value(self): def test_settings_negative_value(self):
self.assertIn('error', self.conf({'http': { 'max_body_size': -1 }}, self.assertIn('error', self.conf({'http': { 'max_body_size': -1 }},
'/settings'), 'settings negative value') 'settings'), 'settings negative value')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@@ -334,8 +334,8 @@ class TestUnitControl(TestUnitHTTP):
if isinstance(conf, dict): if isinstance(conf, dict):
conf = json.dumps(conf) conf = json.dumps(conf)
if path != '/config': if path[:1] != '/':
path = '/config' + path path = '/config/' + path
return json.loads(self.put( return json.loads(self.put(
url=path, url=path,
@@ -345,8 +345,8 @@ class TestUnitControl(TestUnitHTTP):
)['body']) )['body'])
def conf_get(self, path='/config'): def conf_get(self, path='/config'):
if path != '/config': if path[:1] != '/':
path = '/config' + path path = '/config/' + path
return json.loads(self.get( return json.loads(self.get(
url=path, url=path,
@@ -355,8 +355,8 @@ class TestUnitControl(TestUnitHTTP):
)['body']) )['body'])
def conf_delete(self, path='/config'): def conf_delete(self, path='/config'):
if path != '/config': if path[:1] != '/':
path = '/config' + path path = '/config/' + path
return json.loads(self.delete( return json.loads(self.delete(
url=path, url=path,