1 | # -*- coding: utf-8 -*- |
---|
2 | |
---|
3 | """ Unit tests for compileapp.py """ |
---|
4 | |
---|
5 | import unittest |
---|
6 | import os |
---|
7 | import tempfile |
---|
8 | import shutil |
---|
9 | |
---|
10 | from gluon.fileutils import create_app, w2p_pack, w2p_unpack |
---|
11 | from gluon.compileapp import compile_application, remove_compiled_application |
---|
12 | from gluon.globals import Request |
---|
13 | from gluon.admin import (app_compile, app_create, app_cleanup, |
---|
14 | app_uninstall, check_new_version) |
---|
15 | from gluon.main import global_settings |
---|
16 | |
---|
17 | test_app_name = '_test_compileapp' |
---|
18 | test_app2_name = '_test_compileapp_admin' |
---|
19 | test_unpack_dir = None |
---|
20 | |
---|
21 | WEB2PY_VERSION_URL = "http://web2py.com/examples/default/version" |
---|
22 | |
---|
23 | class TestPack(unittest.TestCase): |
---|
24 | """ Tests the compileapp.py module """ |
---|
25 | |
---|
26 | @classmethod |
---|
27 | def setUpClass(cls): |
---|
28 | appdir = os.path.join('applications', test_app_name) |
---|
29 | if not os.path.exists(appdir): |
---|
30 | os.mkdir(appdir) |
---|
31 | create_app(appdir) |
---|
32 | |
---|
33 | @classmethod |
---|
34 | def tearDownClass(cls): |
---|
35 | appdir = os.path.join('applications', test_app_name) |
---|
36 | if os.path.exists(appdir): |
---|
37 | shutil.rmtree(appdir) |
---|
38 | test_pack = "%s.w2p" % test_app_name |
---|
39 | if os.path.exists(test_pack): |
---|
40 | os.unlink(test_pack) |
---|
41 | if test_unpack_dir: |
---|
42 | shutil.rmtree(test_unpack_dir) |
---|
43 | |
---|
44 | def test_compile(self): |
---|
45 | cwd = os.getcwd() |
---|
46 | app_path = os.path.join(cwd, 'applications', test_app_name) |
---|
47 | self.assertIsNone(compile_application(app_path)) |
---|
48 | remove_compiled_application(app_path) |
---|
49 | test_pack = os.path.join(cwd, "%s.w2p" % test_app_name) |
---|
50 | w2p_pack(test_pack, app_path, compiled=True, filenames=None) |
---|
51 | w2p_pack(test_pack, app_path, compiled=False, filenames=None) |
---|
52 | global test_unpack_dir |
---|
53 | test_unpack_dir = tempfile.mkdtemp() |
---|
54 | w2p_unpack(test_pack, test_unpack_dir) |
---|
55 | |
---|
56 | def test_admin_compile(self): |
---|
57 | request = Request(env={}) |
---|
58 | request.application = 'a' |
---|
59 | request.controller = 'c' |
---|
60 | request.function = 'f' |
---|
61 | request.folder = 'applications/admin' |
---|
62 | # remove any existing test app |
---|
63 | app_path = os.path.join('applications', test_app2_name) |
---|
64 | if os.path.exists(app_path): |
---|
65 | shutil.rmtree(app_path) |
---|
66 | |
---|
67 | self.assertTrue(app_create(test_app2_name, request)) |
---|
68 | self.assertTrue(os.path.exists('applications/%s/controllers/default.py' % test_app2_name)) |
---|
69 | self.assertIsNone(app_compile(test_app2_name, request)) |
---|
70 | self.assertTrue(app_cleanup(test_app2_name, request)) |
---|
71 | self.assertTrue(app_uninstall(test_app2_name, request)) |
---|
72 | |
---|
73 | def test_check_new_version(self): |
---|
74 | vert = check_new_version(global_settings.web2py_version, WEB2PY_VERSION_URL) |
---|
75 | self.assertNotEqual(vert[0], -1) |
---|