use testing app, not welcome for test_web, thanks Paolo
This commit is contained in:
+1
-1
Submodule gluon/packages/dal updated: cd9e8fd84b...169ac00734
@@ -1,58 +1,75 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
""" Unit tests for utils.py """
|
""" Unit tests for compileapp.py """
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
from gluon.fileutils import create_app, w2p_pack, w2p_unpack
|
||||||
from gluon.compileapp import compile_application, remove_compiled_application
|
from gluon.compileapp import compile_application, remove_compiled_application
|
||||||
from gluon.fileutils import w2p_pack, w2p_unpack
|
|
||||||
from gluon.globals import Request
|
from gluon.globals import Request
|
||||||
from gluon.admin import app_compile, app_create, app_cleanup, check_new_version
|
from gluon.admin import (app_compile, app_create, app_cleanup,
|
||||||
from gluon.admin import app_uninstall
|
app_uninstall, check_new_version)
|
||||||
from gluon.main import global_settings
|
from gluon.main import global_settings
|
||||||
|
|
||||||
|
test_app_name = '_test_compileapp'
|
||||||
|
test_app2_name = '_test_compileapp_admin'
|
||||||
|
test_unpack_dir = None
|
||||||
|
|
||||||
WEB2PY_VERSION_URL = "http://web2py.com/examples/default/version"
|
WEB2PY_VERSION_URL = "http://web2py.com/examples/default/version"
|
||||||
|
|
||||||
|
|
||||||
class TestPack(unittest.TestCase):
|
class TestPack(unittest.TestCase):
|
||||||
""" Tests the compileapp.py module """
|
""" Tests the compileapp.py module """
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
appdir = os.path.join('applications', test_app_name)
|
||||||
|
if not os.path.exists(appdir):
|
||||||
|
os.mkdir(appdir)
|
||||||
|
create_app(appdir)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
appdir = os.path.join('applications', test_app_name)
|
||||||
|
if os.path.exists(appdir):
|
||||||
|
shutil.rmtree(appdir)
|
||||||
|
test_pack = "%s.w2p" % test_app_name
|
||||||
|
if os.path.exists(test_pack):
|
||||||
|
os.unlink(test_pack)
|
||||||
|
if test_unpack_dir:
|
||||||
|
shutil.rmtree(test_unpack_dir)
|
||||||
|
|
||||||
def test_compile(self):
|
def test_compile(self):
|
||||||
#apps = ['welcome', 'admin', 'examples']
|
cwd = os.getcwd()
|
||||||
apps = ['welcome']
|
app_path = os.path.join(cwd, 'applications', test_app_name)
|
||||||
for appname in apps:
|
self.assertIsNone(compile_application(app_path))
|
||||||
appname_path = os.path.join(os.getcwd(), 'applications', appname)
|
remove_compiled_application(app_path)
|
||||||
compile_application(appname_path)
|
test_pack = os.path.join(cwd, "%s.w2p" % test_app_name)
|
||||||
remove_compiled_application(appname_path)
|
w2p_pack(test_pack, app_path, compiled=True, filenames=None)
|
||||||
test_path = os.path.join(os.getcwd(), "%s.w2p" % appname)
|
w2p_pack(test_pack, app_path, compiled=False, filenames=None)
|
||||||
unpack_path = os.path.join(os.getcwd(), 'unpack', appname)
|
global test_unpack_dir
|
||||||
w2p_pack(test_path, appname_path, compiled=True, filenames=None)
|
test_unpack_dir = tempfile.mkdtemp()
|
||||||
w2p_pack(test_path, appname_path, compiled=False, filenames=None)
|
w2p_unpack(test_pack, test_unpack_dir)
|
||||||
w2p_unpack(test_path, unpack_path)
|
|
||||||
return
|
|
||||||
|
|
||||||
def test_admin_compile(self):
|
def test_admin_compile(self):
|
||||||
#apps = ['welcome', 'admin', 'examples']
|
|
||||||
request = Request(env={})
|
request = Request(env={})
|
||||||
request.application = 'a'
|
request.application = 'a'
|
||||||
request.controller = 'c'
|
request.controller = 'c'
|
||||||
request.function = 'f'
|
request.function = 'f'
|
||||||
request.folder = 'applications/admin'
|
request.folder = 'applications/admin'
|
||||||
apps = ['welcome']
|
# remove any existing test app
|
||||||
for appname in apps:
|
app_path = os.path.join('applications', test_app2_name)
|
||||||
appname_path = os.path.join(os.getcwd(), 'applications', appname)
|
if os.path.exists(app_path):
|
||||||
self.assertEqual(app_compile(appname_path, request), None)
|
shutil.rmtree(app_path)
|
||||||
# remove any existing test_app
|
|
||||||
new_app = 'test_app_%s' % (appname)
|
self.assertTrue(app_create(test_app2_name, request))
|
||||||
if(os.path.exists('applications/%s' % (new_app))):
|
self.assertTrue(os.path.exists('applications/%s/controllers/default.py' % test_app2_name))
|
||||||
shutil.rmtree('applications/%s' % (new_app))
|
self.assertIsNone(app_compile(test_app2_name, request))
|
||||||
self.assertEqual(app_create(new_app, request), True)
|
self.assertTrue(app_cleanup(test_app2_name, request))
|
||||||
self.assertEqual(os.path.exists('applications/test_app_%s/controllers/default.py' % (appname)), True)
|
self.assertTrue(app_uninstall(test_app2_name, request))
|
||||||
self.assertEqual(app_cleanup(new_app, request), True)
|
|
||||||
self.assertEqual(app_uninstall(new_app, request), True)
|
def test_check_new_version(self):
|
||||||
self.assertNotEqual(check_new_version(global_settings.web2py_version, WEB2PY_VERSION_URL), -1)
|
vert = check_new_version(global_settings.web2py_version, WEB2PY_VERSION_URL)
|
||||||
return
|
self.assertNotEqual(vert[0], -1)
|
||||||
|
|||||||
+9
-18
@@ -14,8 +14,9 @@ import shutil
|
|||||||
|
|
||||||
from gluon.contrib.webclient import WebClient
|
from gluon.contrib.webclient import WebClient
|
||||||
from gluon._compat import urllib2, PY2
|
from gluon._compat import urllib2, PY2
|
||||||
|
from gluon.fileutils import create_app
|
||||||
|
|
||||||
test_app_name = 'welcome'
|
test_app_name = '_test_web'
|
||||||
|
|
||||||
webserverprocess = None
|
webserverprocess = None
|
||||||
|
|
||||||
@@ -72,28 +73,18 @@ class LiveTest(unittest.TestCase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
# FIXME: should use a temporary application to run tests,
|
appdir = os.path.join('applications', test_app_name)
|
||||||
# instead of tampering an existing one, whatever it is;
|
if not os.path.exists(appdir):
|
||||||
# rename databases dir to databases~ and use a blank
|
os.mkdir(appdir)
|
||||||
# databases during tests
|
create_app(appdir)
|
||||||
dbdir = os.path.join('applications', test_app_name, 'databases')
|
|
||||||
if os.path.exists(dbdir):
|
|
||||||
bakdbdir = dbdir + '~'
|
|
||||||
if os.path.exists(bakdbdir):
|
|
||||||
shutil.rmtree(dbdir)
|
|
||||||
else:
|
|
||||||
os.rename(dbdir, bakdbdir)
|
|
||||||
os.mkdir(dbdir)
|
|
||||||
startwebserver()
|
startwebserver()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
stopwebserver()
|
stopwebserver()
|
||||||
dbdir = os.path.join('applications', test_app_name, 'databases')
|
appdir = os.path.join('applications', test_app_name)
|
||||||
shutil.rmtree(dbdir)
|
if os.path.exists(appdir):
|
||||||
bakdbdir = dbdir + '~'
|
shutil.rmtree(appdir)
|
||||||
if os.path.exists(bakdbdir):
|
|
||||||
os.rename(bakdbdir, dbdir)
|
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf("datastore" in os.getenv("DB", ""), "TODO: setup web test for app engine")
|
@unittest.skipIf("datastore" in os.getenv("DB", ""), "TODO: setup web test for app engine")
|
||||||
|
|||||||
Reference in New Issue
Block a user