Tests: added methods to manage unit configuration.
This commit is contained in:
@@ -7,10 +7,10 @@ class TestUnitConfiguration(unit.TestUnitControl):
|
|||||||
unit.TestUnit().check_modules('python')
|
unit.TestUnit().check_modules('python')
|
||||||
|
|
||||||
def test_json_leading_zero(self):
|
def test_json_leading_zero(self):
|
||||||
self.assertIn('error', self.put('/', '00'), 'leading zero')
|
self.assertIn('error', self.conf('00'), 'leading zero')
|
||||||
|
|
||||||
def test_json_unicode(self):
|
def test_json_unicode(self):
|
||||||
self.assertIn('success', self.put('/applications', b"""
|
self.assertIn('success', self.conf(b"""
|
||||||
{
|
{
|
||||||
"ap\u0070": {
|
"ap\u0070": {
|
||||||
"type": "\u0070ython",
|
"type": "\u0070ython",
|
||||||
@@ -19,22 +19,20 @@ class TestUnitConfiguration(unit.TestUnitControl):
|
|||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""), 'unicode')
|
""", '/applications'), 'unicode')
|
||||||
|
|
||||||
def test_json_unicode_2(self):
|
def test_json_unicode_2(self):
|
||||||
self.assertIn('success', self.put('/applications', """
|
self.assertIn('success', self.conf({
|
||||||
{
|
|
||||||
"приложение": {
|
"приложение": {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"workers": 1,
|
"workers": 1,
|
||||||
"path": "/app",
|
"path": "/app",
|
||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}, '/applications'), 'unicode 2')
|
||||||
"""), 'unicode 2')
|
|
||||||
|
|
||||||
def test_json_unicode_number(self):
|
def test_json_unicode_number(self):
|
||||||
self.assertIn('error', self.put('/applications', b"""
|
self.assertIn('error', self.conf(b"""
|
||||||
{
|
{
|
||||||
"app": {
|
"app": {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
@@ -43,39 +41,35 @@ class TestUnitConfiguration(unit.TestUnitControl):
|
|||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""), 'unicode number')
|
""", '/applications'), 'unicode number')
|
||||||
|
|
||||||
def test_applications_open_brace(self):
|
def test_applications_open_brace(self):
|
||||||
self.assertIn('error', self.put('/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.put('/applications', '"{}"'), 'string')
|
self.assertIn('error', self.conf('"{}"', '/applications'), 'string')
|
||||||
|
|
||||||
@unittest.expectedFailure
|
@unittest.expectedFailure
|
||||||
def test_negative_workers(self):
|
def test_negative_workers(self):
|
||||||
self.assertIn('error', self.put('/applications', """
|
self.assertIn('error', self.conf({
|
||||||
{
|
|
||||||
"app": {
|
"app": {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"workers": -1,
|
"workers": -1,
|
||||||
"path": "/app",
|
"path": "/app",
|
||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}, '/applications'), 'negative workers')
|
||||||
"""), 'negative workers')
|
|
||||||
|
|
||||||
@unittest.expectedFailure
|
@unittest.expectedFailure
|
||||||
def test_applications_type_only(self):
|
def test_applications_type_only(self):
|
||||||
self.assertIn('error', self.put('/applications', """
|
self.assertIn('error', self.conf({
|
||||||
{
|
|
||||||
"app": {
|
"app": {
|
||||||
"type": "python"
|
"type": "python"
|
||||||
}
|
}
|
||||||
}
|
}, '/applications'), 'type only')
|
||||||
"""), 'type only')
|
|
||||||
|
|
||||||
def test_applications_miss_quote(self):
|
def test_applications_miss_quote(self):
|
||||||
self.assertIn('error', self.put('/applications', """
|
self.assertIn('error', self.conf("""
|
||||||
{
|
{
|
||||||
app": {
|
app": {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
@@ -84,10 +78,10 @@ class TestUnitConfiguration(unit.TestUnitControl):
|
|||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""), 'miss quote')
|
""", '/applications'), 'miss quote')
|
||||||
|
|
||||||
def test_applications_miss_colon(self):
|
def test_applications_miss_colon(self):
|
||||||
self.assertIn('error', self.put('/applications', """
|
self.assertIn('error', self.conf("""
|
||||||
{
|
{
|
||||||
"app" {
|
"app" {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
@@ -96,10 +90,10 @@ class TestUnitConfiguration(unit.TestUnitControl):
|
|||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""), 'miss colon')
|
""", '/applications'), 'miss colon')
|
||||||
|
|
||||||
def test_applications_miss_comma(self):
|
def test_applications_miss_comma(self):
|
||||||
self.assertIn('error', self.put('/applications', """
|
self.assertIn('error', self.conf("""
|
||||||
{
|
{
|
||||||
"app": {
|
"app": {
|
||||||
"type": "python"
|
"type": "python"
|
||||||
@@ -108,36 +102,33 @@ class TestUnitConfiguration(unit.TestUnitControl):
|
|||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""), 'miss comma')
|
""", '/applications'), 'miss comma')
|
||||||
|
|
||||||
def test_applications_skip_spaces(self):
|
def test_applications_skip_spaces(self):
|
||||||
self.assertIn('success', self.put('/applications', b'{ \n\r\t}'),
|
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):
|
||||||
self.assertIn('success', self.put('/applications', """
|
self.assertIn('success', self.conf({
|
||||||
{
|
|
||||||
"app": {
|
"app": {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"workers": 1,
|
"workers": 1,
|
||||||
"path": "../app",
|
"path": "../app",
|
||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}, '/applications'), 'relative path')
|
||||||
"""), 'relative path')
|
|
||||||
|
|
||||||
@unittest.expectedFailure
|
@unittest.expectedFailure
|
||||||
def test_listeners_empty(self):
|
def test_listeners_empty(self):
|
||||||
self.assertIn('error', self.put('/listeners', '{"*:7080":{}}'),
|
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.put('/listeners',
|
self.assertIn('error', self.conf({"*:7080":{"application":"app"}},
|
||||||
'{"*:7080":{"application":"app"}}'), 'listeners no app')
|
'/listeners'), 'listeners no app')
|
||||||
|
|
||||||
def test_listeners_wildcard(self):
|
def test_listeners_wildcard(self):
|
||||||
self.assertIn('success', self.put('/', """
|
self.assertIn('success', self.conf({
|
||||||
{
|
|
||||||
"listeners": {
|
"listeners": {
|
||||||
"*:7080": {
|
"*:7080": {
|
||||||
"application":"app"
|
"application":"app"
|
||||||
@@ -151,12 +142,10 @@ class TestUnitConfiguration(unit.TestUnitControl):
|
|||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}), 'listeners wildcard')
|
||||||
"""), 'listeners wildcard')
|
|
||||||
|
|
||||||
def test_listeners_explicit(self):
|
def test_listeners_explicit(self):
|
||||||
self.assertIn('success', self.put('/', """
|
self.assertIn('success', self.conf({
|
||||||
{
|
|
||||||
"listeners": {
|
"listeners": {
|
||||||
"127.0.0.1:7080": {
|
"127.0.0.1:7080": {
|
||||||
"application":"app"
|
"application":"app"
|
||||||
@@ -170,12 +159,10 @@ class TestUnitConfiguration(unit.TestUnitControl):
|
|||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}), 'explicit')
|
||||||
"""), 'explicit')
|
|
||||||
|
|
||||||
def test_listeners_explicit_ipv6(self):
|
def test_listeners_explicit_ipv6(self):
|
||||||
self.assertIn('success', self.put('/', """
|
self.assertIn('success', self.conf({
|
||||||
{
|
|
||||||
"listeners": {
|
"listeners": {
|
||||||
"[::1]:7080": {
|
"[::1]:7080": {
|
||||||
"application":"app"
|
"application":"app"
|
||||||
@@ -189,12 +176,10 @@ class TestUnitConfiguration(unit.TestUnitControl):
|
|||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}), 'explicit ipv6')
|
||||||
"""), 'explicit ipv6')
|
|
||||||
|
|
||||||
def test_listeners_no_port(self):
|
def test_listeners_no_port(self):
|
||||||
self.assertIn('error', self.put('/', """
|
self.assertIn('error', self.conf({
|
||||||
{
|
|
||||||
"listeners": {
|
"listeners": {
|
||||||
"127.0.0.1": {
|
"127.0.0.1": {
|
||||||
"application":"app"
|
"application":"app"
|
||||||
@@ -208,8 +193,7 @@ class TestUnitConfiguration(unit.TestUnitControl):
|
|||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}), 'no port')
|
||||||
"""), 'no port')
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ class TestUnitBasic(unit.TestUnitControl):
|
|||||||
def setUpClass():
|
def setUpClass():
|
||||||
unit.TestUnit().check_modules('php')
|
unit.TestUnit().check_modules('php')
|
||||||
|
|
||||||
conf_app = """
|
conf_app = {
|
||||||
{
|
|
||||||
"app": {
|
"app": {
|
||||||
"type": "php",
|
"type": "php",
|
||||||
"workers": 1,
|
"workers": 1,
|
||||||
@@ -15,26 +14,23 @@ class TestUnitBasic(unit.TestUnitControl):
|
|||||||
"index": "index.php"
|
"index": "index.php"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
|
||||||
|
|
||||||
conf_basic = """
|
conf_basic = {
|
||||||
{
|
|
||||||
"listeners": {
|
"listeners": {
|
||||||
"*:7080": {
|
"*:7080": {
|
||||||
"application": "app"
|
"application": "app"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"applications": %s
|
"applications": conf_app
|
||||||
}
|
}
|
||||||
""" % (conf_app)
|
|
||||||
|
|
||||||
def test_php_get_applications(self):
|
def test_php_get_applications(self):
|
||||||
self.put('/applications', self.conf_app)
|
self.conf(self.conf_app, '/applications')
|
||||||
|
|
||||||
resp = self.get()
|
conf = self.conf_get()
|
||||||
|
|
||||||
self.assertEqual(resp['listeners'], {}, 'listeners')
|
self.assertEqual(conf['listeners'], {}, 'listeners')
|
||||||
self.assertEqual(resp['applications'],
|
self.assertEqual(conf['applications'],
|
||||||
{
|
{
|
||||||
"app": {
|
"app": {
|
||||||
"type": "php",
|
"type": "php",
|
||||||
@@ -46,9 +42,9 @@ class TestUnitBasic(unit.TestUnitControl):
|
|||||||
'applications')
|
'applications')
|
||||||
|
|
||||||
def test_php_get_applications_prefix(self):
|
def test_php_get_applications_prefix(self):
|
||||||
self.put('/applications', self.conf_app)
|
self.conf(self.conf_app, '/applications')
|
||||||
|
|
||||||
self.assertEqual(self.get('/applications'),
|
self.assertEqual(self.conf_get('/applications'),
|
||||||
{
|
{
|
||||||
"app": {
|
"app": {
|
||||||
"type": "php",
|
"type": "php",
|
||||||
@@ -60,9 +56,9 @@ class TestUnitBasic(unit.TestUnitControl):
|
|||||||
'applications prefix')
|
'applications prefix')
|
||||||
|
|
||||||
def test_php_get_applications_prefix_2(self):
|
def test_php_get_applications_prefix_2(self):
|
||||||
self.put('/applications', self.conf_app)
|
self.conf(self.conf_app, '/applications')
|
||||||
|
|
||||||
self.assertEqual(self.get('/applications/app'),
|
self.assertEqual(self.conf_get('/applications/app'),
|
||||||
{
|
{
|
||||||
"type": "php",
|
"type": "php",
|
||||||
"workers": 1,
|
"workers": 1,
|
||||||
@@ -72,41 +68,43 @@ class TestUnitBasic(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.put('/applications', self.conf_app)
|
self.conf(self.conf_app, '/applications')
|
||||||
|
|
||||||
self.assertEqual(self.get('/applications/app/type'), 'php', 'type')
|
self.assertEqual(self.conf_get('/applications/app/type'), 'php',
|
||||||
self.assertEqual(self.get('/applications/app/workers'), 1, 'workers')
|
'type')
|
||||||
|
self.assertEqual(self.conf_get('/applications/app/workers'), 1,
|
||||||
|
'workers')
|
||||||
|
|
||||||
def test_php_get_listeners(self):
|
def test_php_get_listeners(self):
|
||||||
self.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
|
|
||||||
self.assertEqual(self.get()['listeners'],
|
self.assertEqual(self.conf_get()['listeners'],
|
||||||
{"*:7080":{"application":"app"}}, 'listeners')
|
{"*:7080":{"application":"app"}}, 'listeners')
|
||||||
|
|
||||||
def test_php_get_listeners_prefix(self):
|
def test_php_get_listeners_prefix(self):
|
||||||
self.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
|
|
||||||
self.assertEqual(self.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.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
|
|
||||||
self.assertEqual(self.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.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
self.put('/listeners', '{"*:7081":{"application":"app"}}')
|
self.conf({"*:7081":{"application":"app"}}, '/listeners')
|
||||||
|
|
||||||
self.assertEqual(self.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.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
self.put('/listeners/*:7082', '{"application":"app"}')
|
self.conf({"application":"app"}, '/listeners/*:7082')
|
||||||
|
|
||||||
self.assertEqual(self.get('/listeners'),
|
self.assertEqual(self.conf_get('/listeners'),
|
||||||
{
|
{
|
||||||
"*:7080": {
|
"*:7080": {
|
||||||
"application": "app"
|
"application": "app"
|
||||||
@@ -118,26 +116,26 @@ class TestUnitBasic(unit.TestUnitControl):
|
|||||||
'add listener')
|
'add listener')
|
||||||
|
|
||||||
def test_php_change_application(self):
|
def test_php_change_application(self):
|
||||||
self.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
|
|
||||||
self.put('/applications/app/workers', '30')
|
self.conf('30', '/applications/app/workers')
|
||||||
self.assertEqual(self.get('/applications/app/workers'), 30,
|
self.assertEqual(self.conf_get('/applications/app/workers'), 30,
|
||||||
'change application workers')
|
'change application workers')
|
||||||
|
|
||||||
self.put('/applications/app/root', '"/www"')
|
self.conf('"/www"', '/applications/app/root')
|
||||||
self.assertEqual(self.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.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
|
|
||||||
self.assertIn('error', self.delete('/applications/app'),
|
self.assertIn('error', self.conf_delete('/applications/app'),
|
||||||
'delete app before listener')
|
'delete app before listener')
|
||||||
self.assertIn('success', self.delete('/listeners/*:7080'),
|
self.assertIn('success', self.conf_delete('/listeners/*:7080'),
|
||||||
'delete listener')
|
'delete listener')
|
||||||
self.assertIn('success', self.delete('/applications/app'),
|
self.assertIn('success', self.conf_delete('/applications/app'),
|
||||||
'delete app after listener')
|
'delete app after listener')
|
||||||
self.assertIn('error', self.delete('/applications/app'),
|
self.assertIn('error', self.conf_delete('/applications/app'),
|
||||||
'delete app again')
|
'delete app again')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ class TestUnitApplication(unit.TestUnitControl):
|
|||||||
u.check_modules('python')
|
u.check_modules('python')
|
||||||
u.check_version('0.4')
|
u.check_version('0.4')
|
||||||
|
|
||||||
conf = """
|
def conf_with_name(self, name):
|
||||||
{
|
self.conf({
|
||||||
"listeners": {
|
"listeners": {
|
||||||
"*:7080": {
|
"*:7080": {
|
||||||
"application": "app"
|
"application": "app"
|
||||||
@@ -20,12 +20,11 @@ class TestUnitApplication(unit.TestUnitControl):
|
|||||||
"app": {
|
"app": {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"workers": 1,
|
"workers": 1,
|
||||||
"path": "%s",
|
"path": self.testdir + '/' + name,
|
||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
"""
|
|
||||||
|
|
||||||
def test_python_application_simple(self):
|
def test_python_application_simple(self):
|
||||||
code, name = """
|
code, name = """
|
||||||
@@ -49,7 +48,7 @@ def application(environ, start_response):
|
|||||||
""", 'py_app'
|
""", 'py_app'
|
||||||
|
|
||||||
self.python_application(name, code)
|
self.python_application(name, code)
|
||||||
self.put('/', self.conf % (self.testdir + '/' + name))
|
self.conf_with_name(name)
|
||||||
|
|
||||||
body = 'Test body string.'
|
body = 'Test body string.'
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ def application(environ, start_response):
|
|||||||
""", 'py_app'
|
""", 'py_app'
|
||||||
|
|
||||||
self.python_application(name, code)
|
self.python_application(name, code)
|
||||||
self.put('/', self.conf % (self.testdir + '/' + name))
|
self.conf_with_name(name)
|
||||||
|
|
||||||
r = unit.TestUnitHTTP.get(uri='/?var1=val1&var2=val2', headers={
|
r = unit.TestUnitHTTP.get(uri='/?var1=val1&var2=val2', headers={
|
||||||
'Host': 'localhost'
|
'Host': 'localhost'
|
||||||
@@ -117,7 +116,7 @@ def application(environ, start_response):
|
|||||||
""", 'py_app'
|
""", 'py_app'
|
||||||
|
|
||||||
self.python_application(name, code)
|
self.python_application(name, code)
|
||||||
self.put('/', self.conf % (self.testdir + '/' + name))
|
self.conf_with_name(name)
|
||||||
|
|
||||||
r = unit.TestUnitHTTP.get(headers={'Host': 'localhost'})
|
r = unit.TestUnitHTTP.get(headers={'Host': 'localhost'})
|
||||||
|
|
||||||
@@ -136,7 +135,7 @@ def application(environ, start_response):
|
|||||||
""", 'py_app'
|
""", 'py_app'
|
||||||
|
|
||||||
self.python_application(name, code)
|
self.python_application(name, code)
|
||||||
self.put('/', self.conf % (self.testdir + '/' + name))
|
self.conf_with_name(name)
|
||||||
|
|
||||||
r = unit.TestUnitHTTP.get(headers={'Host': 'localhost'})
|
r = unit.TestUnitHTTP.get(headers={'Host': 'localhost'})
|
||||||
self.assertNotIn('Transfer-Encoding', r.headers,
|
self.assertNotIn('Transfer-Encoding', r.headers,
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ def application(env, start_response):
|
|||||||
|
|
||||||
self.python_application(name, code)
|
self.python_application(name, code)
|
||||||
|
|
||||||
self.put('/', """
|
self.conf({
|
||||||
{
|
|
||||||
"listeners": {
|
"listeners": {
|
||||||
"*:7080": {
|
"*:7080": {
|
||||||
"application": "app"
|
"application": "app"
|
||||||
@@ -39,21 +38,18 @@ def application(env, start_response):
|
|||||||
"app": {
|
"app": {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"workers": 1,
|
"workers": 1,
|
||||||
"path": "%s",
|
"path": self.testdir + '/' + name,
|
||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
""" % (self.testdir + '/' + name))
|
|
||||||
|
|
||||||
unit.TestUnitHTTP.get()
|
unit.TestUnitHTTP.get()
|
||||||
|
|
||||||
self.put('/', """
|
self.conf({
|
||||||
{
|
|
||||||
"listeners": {},
|
"listeners": {},
|
||||||
"applications": {}
|
"applications": {}
|
||||||
}
|
})
|
||||||
""")
|
|
||||||
|
|
||||||
time.sleep(0.2) # wait for 'atexit' file
|
time.sleep(0.2) # wait for 'atexit' file
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ class TestUnitBasic(unit.TestUnitControl):
|
|||||||
def setUpClass():
|
def setUpClass():
|
||||||
unit.TestUnit().check_modules('python')
|
unit.TestUnit().check_modules('python')
|
||||||
|
|
||||||
conf_app = """
|
conf_app = {
|
||||||
{
|
|
||||||
"app": {
|
"app": {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"workers": 1,
|
"workers": 1,
|
||||||
@@ -15,36 +14,33 @@ class TestUnitBasic(unit.TestUnitControl):
|
|||||||
"module": "wsgi"
|
"module": "wsgi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
|
||||||
|
|
||||||
conf_basic = """
|
conf_basic = {
|
||||||
{
|
|
||||||
"listeners": {
|
"listeners": {
|
||||||
"*:7080": {
|
"*:7080": {
|
||||||
"application": "app"
|
"application": "app"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"applications": %s
|
"applications": conf_app
|
||||||
}
|
}
|
||||||
""" % (conf_app)
|
|
||||||
|
|
||||||
def test_python_get_empty(self):
|
def test_python_get_empty(self):
|
||||||
self.assertEqual(self.get(), {'listeners': {}, 'applications': {}},
|
self.assertEqual(self.conf_get(),
|
||||||
'empty')
|
{'listeners': {}, 'applications': {}}, 'empty')
|
||||||
|
|
||||||
def test_python_get_prefix_listeners(self):
|
def test_python_get_prefix_listeners(self):
|
||||||
self.assertEqual(self.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.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.put('/applications', self.conf_app)
|
self.conf(self.conf_app, '/applications')
|
||||||
|
|
||||||
resp = self.get()
|
conf = self.conf_get()
|
||||||
|
|
||||||
self.assertEqual(resp['listeners'], {}, 'listeners')
|
self.assertEqual(conf['listeners'], {}, 'listeners')
|
||||||
self.assertEqual(resp['applications'],
|
self.assertEqual(conf['applications'],
|
||||||
{
|
{
|
||||||
"app": {
|
"app": {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
@@ -56,9 +52,9 @@ class TestUnitBasic(unit.TestUnitControl):
|
|||||||
'applications')
|
'applications')
|
||||||
|
|
||||||
def test_python_get_applications_prefix(self):
|
def test_python_get_applications_prefix(self):
|
||||||
self.put('/applications', self.conf_app)
|
self.conf(self.conf_app, '/applications')
|
||||||
|
|
||||||
self.assertEqual(self.get('/applications'),
|
self.assertEqual(self.conf_get('/applications'),
|
||||||
{
|
{
|
||||||
"app": {
|
"app": {
|
||||||
"type": "python",
|
"type": "python",
|
||||||
@@ -70,9 +66,9 @@ class TestUnitBasic(unit.TestUnitControl):
|
|||||||
'applications prefix')
|
'applications prefix')
|
||||||
|
|
||||||
def test_python_get_applications_prefix_2(self):
|
def test_python_get_applications_prefix_2(self):
|
||||||
self.put('/applications', self.conf_app)
|
self.conf(self.conf_app, '/applications')
|
||||||
|
|
||||||
self.assertEqual(self.get('/applications/app'),
|
self.assertEqual(self.conf_get('/applications/app'),
|
||||||
{
|
{
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"workers": 1,
|
"workers": 1,
|
||||||
@@ -82,41 +78,43 @@ class TestUnitBasic(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.put('/applications', self.conf_app)
|
self.conf(self.conf_app, '/applications')
|
||||||
|
|
||||||
self.assertEqual(self.get('/applications/app/type'), 'python', 'type')
|
self.assertEqual(self.conf_get('/applications/app/type'), 'python',
|
||||||
self.assertEqual(self.get('/applications/app/workers'), 1, 'workers')
|
'type')
|
||||||
|
self.assertEqual(self.conf_get('/applications/app/workers'), 1,
|
||||||
|
'workers')
|
||||||
|
|
||||||
def test_python_get_listeners(self):
|
def test_python_get_listeners(self):
|
||||||
self.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
|
|
||||||
self.assertEqual(self.get()['listeners'],
|
self.assertEqual(self.conf_get()['listeners'],
|
||||||
{"*:7080":{"application":"app"}}, 'listeners')
|
{"*:7080":{"application":"app"}}, 'listeners')
|
||||||
|
|
||||||
def test_python_get_listeners_prefix(self):
|
def test_python_get_listeners_prefix(self):
|
||||||
self.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
|
|
||||||
self.assertEqual(self.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.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
|
|
||||||
self.assertEqual(self.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.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
self.put('/listeners', '{"*:7081":{"application":"app"}}')
|
self.conf({"*:7081":{"application":"app"}}, '/listeners')
|
||||||
|
|
||||||
self.assertEqual(self.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.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
self.put('/listeners/*:7082', '{"application":"app"}')
|
self.conf({"application":"app"}, '/listeners/*:7082')
|
||||||
|
|
||||||
self.assertEqual(self.get('/listeners'),
|
self.assertEqual(self.conf_get('/listeners'),
|
||||||
{
|
{
|
||||||
"*:7080": {
|
"*:7080": {
|
||||||
"application": "app"
|
"application": "app"
|
||||||
@@ -128,26 +126,26 @@ class TestUnitBasic(unit.TestUnitControl):
|
|||||||
'add listener')
|
'add listener')
|
||||||
|
|
||||||
def test_python_change_application(self):
|
def test_python_change_application(self):
|
||||||
self.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
|
|
||||||
self.put('/applications/app/workers', '30')
|
self.conf('30', '/applications/app/workers')
|
||||||
self.assertEqual(self.get('/applications/app/workers'), 30,
|
self.assertEqual(self.conf_get('/applications/app/workers'), 30,
|
||||||
'change application workers')
|
'change application workers')
|
||||||
|
|
||||||
self.put('/applications/app/path', '"/www"')
|
self.conf('"/www"', '/applications/app/path')
|
||||||
self.assertEqual(self.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.put('/', self.conf_basic)
|
self.conf(self.conf_basic)
|
||||||
|
|
||||||
self.assertIn('error', self.delete('/applications/app'),
|
self.assertIn('error', self.conf_delete('/applications/app'),
|
||||||
'delete app before listener')
|
'delete app before listener')
|
||||||
self.assertIn('success', self.delete('/listeners/*:7080'),
|
self.assertIn('success', self.conf_delete('/listeners/*:7080'),
|
||||||
'delete listener')
|
'delete listener')
|
||||||
self.assertIn('success', self.delete('/applications/app'),
|
self.assertIn('success', self.conf_delete('/applications/app'),
|
||||||
'delete app after listener')
|
'delete app after listener')
|
||||||
self.assertIn('error', self.delete('/applications/app'),
|
self.assertIn('error', self.conf_delete('/applications/app'),
|
||||||
'delete app again')
|
'delete app again')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
18
test/unit.py
18
test/unit.py
@@ -149,6 +149,18 @@ class TestUnitControl(TestUnit):
|
|||||||
# TODO socket reuse
|
# TODO socket reuse
|
||||||
# TODO http client
|
# TODO http client
|
||||||
|
|
||||||
|
def conf(self, conf, path='/'):
|
||||||
|
if isinstance(conf, dict):
|
||||||
|
conf = json.dumps(conf)
|
||||||
|
|
||||||
|
return self._body_json(self.put(path, conf))
|
||||||
|
|
||||||
|
def conf_get(self, path='/'):
|
||||||
|
return self._body_json(self.get(path))
|
||||||
|
|
||||||
|
def conf_delete(self, path='/'):
|
||||||
|
return self._body_json(self.delete(path))
|
||||||
|
|
||||||
def http(self, req):
|
def http(self, req):
|
||||||
with self._control_sock() as sock:
|
with self._control_sock() as sock:
|
||||||
sock.sendall(req)
|
sock.sendall(req)
|
||||||
@@ -167,13 +179,13 @@ class TestUnitControl(TestUnit):
|
|||||||
resp = self.http(('GET ' + path
|
resp = self.http(('GET ' + path
|
||||||
+ ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
|
+ ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
|
||||||
|
|
||||||
return self._body_json(resp)
|
return resp
|
||||||
|
|
||||||
def delete(self, path='/'):
|
def delete(self, path='/'):
|
||||||
resp = self.http(('DELETE ' + path
|
resp = self.http(('DELETE ' + path
|
||||||
+ ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
|
+ ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
|
||||||
|
|
||||||
return self._body_json(resp)
|
return resp
|
||||||
|
|
||||||
def put(self, path='/', data=''):
|
def put(self, path='/', data=''):
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
@@ -183,7 +195,7 @@ class TestUnitControl(TestUnit):
|
|||||||
+ 'Content-Length: ' + str(len(data))
|
+ 'Content-Length: ' + str(len(data))
|
||||||
+ '\r\n\r\n').encode() + data)
|
+ '\r\n\r\n').encode() + data)
|
||||||
|
|
||||||
return self._body_json(resp)
|
return resp
|
||||||
|
|
||||||
def _control_sock(self):
|
def _control_sock(self):
|
||||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
|||||||
Reference in New Issue
Block a user