diff --git a/gluon/packages/dal b/gluon/packages/dal index cd9e8fd8..169ac007 160000 --- a/gluon/packages/dal +++ b/gluon/packages/dal @@ -1 +1 @@ -Subproject commit cd9e8fd84b777a2e35e48d4eab1fc700eceee1a9 +Subproject commit 169ac007347b1119d8afad740b4ca767a9f9195c diff --git a/gluon/tests/test_compileapp.py b/gluon/tests/test_compileapp.py index 95645012..d5a8792c 100644 --- a/gluon/tests/test_compileapp.py +++ b/gluon/tests/test_compileapp.py @@ -1,58 +1,75 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- -""" Unit tests for utils.py """ +""" Unit tests for compileapp.py """ import unittest import os +import tempfile import shutil +from gluon.fileutils import create_app, w2p_pack, w2p_unpack from gluon.compileapp import compile_application, remove_compiled_application -from gluon.fileutils import w2p_pack, w2p_unpack from gluon.globals import Request -from gluon.admin import app_compile, app_create, app_cleanup, check_new_version -from gluon.admin import app_uninstall +from gluon.admin import (app_compile, app_create, app_cleanup, + app_uninstall, check_new_version) 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" - class TestPack(unittest.TestCase): """ 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): - #apps = ['welcome', 'admin', 'examples'] - apps = ['welcome'] - for appname in apps: - appname_path = os.path.join(os.getcwd(), 'applications', appname) - compile_application(appname_path) - remove_compiled_application(appname_path) - test_path = os.path.join(os.getcwd(), "%s.w2p" % appname) - unpack_path = os.path.join(os.getcwd(), 'unpack', appname) - w2p_pack(test_path, appname_path, compiled=True, filenames=None) - w2p_pack(test_path, appname_path, compiled=False, filenames=None) - w2p_unpack(test_path, unpack_path) - return + cwd = os.getcwd() + app_path = os.path.join(cwd, 'applications', test_app_name) + self.assertIsNone(compile_application(app_path)) + remove_compiled_application(app_path) + test_pack = os.path.join(cwd, "%s.w2p" % test_app_name) + w2p_pack(test_pack, app_path, compiled=True, filenames=None) + w2p_pack(test_pack, app_path, compiled=False, filenames=None) + global test_unpack_dir + test_unpack_dir = tempfile.mkdtemp() + w2p_unpack(test_pack, test_unpack_dir) def test_admin_compile(self): - #apps = ['welcome', 'admin', 'examples'] request = Request(env={}) request.application = 'a' request.controller = 'c' request.function = 'f' request.folder = 'applications/admin' - apps = ['welcome'] - for appname in apps: - appname_path = os.path.join(os.getcwd(), 'applications', appname) - self.assertEqual(app_compile(appname_path, request), None) - # remove any existing test_app - new_app = 'test_app_%s' % (appname) - if(os.path.exists('applications/%s' % (new_app))): - shutil.rmtree('applications/%s' % (new_app)) - self.assertEqual(app_create(new_app, request), True) - self.assertEqual(os.path.exists('applications/test_app_%s/controllers/default.py' % (appname)), True) - self.assertEqual(app_cleanup(new_app, request), True) - self.assertEqual(app_uninstall(new_app, request), True) - self.assertNotEqual(check_new_version(global_settings.web2py_version, WEB2PY_VERSION_URL), -1) - return + # remove any existing test app + app_path = os.path.join('applications', test_app2_name) + if os.path.exists(app_path): + shutil.rmtree(app_path) + + self.assertTrue(app_create(test_app2_name, request)) + self.assertTrue(os.path.exists('applications/%s/controllers/default.py' % test_app2_name)) + self.assertIsNone(app_compile(test_app2_name, request)) + self.assertTrue(app_cleanup(test_app2_name, request)) + self.assertTrue(app_uninstall(test_app2_name, request)) + + def test_check_new_version(self): + vert = check_new_version(global_settings.web2py_version, WEB2PY_VERSION_URL) + self.assertNotEqual(vert[0], -1) diff --git a/gluon/tests/test_web.py b/gluon/tests/test_web.py index f55edcf2..0df99c38 100644 --- a/gluon/tests/test_web.py +++ b/gluon/tests/test_web.py @@ -14,8 +14,9 @@ import shutil from gluon.contrib.webclient import WebClient from gluon._compat import urllib2, PY2 +from gluon.fileutils import create_app -test_app_name = 'welcome' +test_app_name = '_test_web' webserverprocess = None @@ -72,28 +73,18 @@ class LiveTest(unittest.TestCase): @classmethod def setUpClass(cls): - # FIXME: should use a temporary application to run tests, - # instead of tampering an existing one, whatever it is; - # rename databases dir to databases~ and use a blank - # databases during tests - 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) + appdir = os.path.join('applications', test_app_name) + if not os.path.exists(appdir): + os.mkdir(appdir) + create_app(appdir) startwebserver() @classmethod def tearDownClass(cls): stopwebserver() - dbdir = os.path.join('applications', test_app_name, 'databases') - shutil.rmtree(dbdir) - bakdbdir = dbdir + '~' - if os.path.exists(bakdbdir): - os.rename(bakdbdir, dbdir) + appdir = os.path.join('applications', test_app_name) + if os.path.exists(appdir): + shutil.rmtree(appdir) @unittest.skipIf("datastore" in os.getenv("DB", ""), "TODO: setup web test for app engine")