diff --git a/CHANGELOG b/CHANGELOG index 208a41a9..5f5c52a9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,8 @@ - py3.5 syntax compatible (see #1353 for details) - dropped web shell from admin - scheduler new feature: you can now specify intervals with cron +- tests can only be run with the usual web2py.py --run_system_tests OR with + python -m unittest -v gluon.tests on the root dir ## 2.14.6 @@ -12,7 +14,7 @@ - Fixed some newly discovered security issues in admin: CSRF vulnerability in admin that allows disabling apps Brute force password attack vulnerability in admin - (thanks Narendra and Leonel) + (thanks Narendra and Leonel) ## 2.14.1-5 @@ -129,7 +131,7 @@ Many thanks to Richard and Simone for their work and dedication. - Added Portuguese, Catalan, and Burmese translations - Allow map_hyphen to work for application names, thanks Tim Nyborg - New module appconfig.py, thanks Niphlod -- Added geospatial support to Teradata adaptor, thanks Andrew Willimott +- Added geospatial support to Teradata adaptor, thanks Andrew Willimott - Many bug fixes diff --git a/gluon/__init__.py b/gluon/__init__.py index c0e306f2..6a5e25f1 100644 --- a/gluon/__init__.py +++ b/gluon/__init__.py @@ -16,8 +16,10 @@ __all__ = ['A', 'B', 'BEAUTIFY', 'BODY', 'BR', 'CAT', 'CENTER', 'CLEANUP', 'CODE import os import sys try: - sys.path.insert(1,os.path.join( - os.path.dirname(os.path.abspath(__file__)), "packages", "dal")) + pydalpath = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "packages", "dal") + if pydalpath not in sys.path: + sys.path.append(pydalpath) import pydal sys.modules['pydal'] = pydal except ImportError: diff --git a/gluon/sql.py b/gluon/sql.py index c70d7295..3339ba07 100644 --- a/gluon/sql.py +++ b/gluon/sql.py @@ -12,7 +12,7 @@ Just for backward compatibility """ __all__ = ['DAL', 'Field', 'DRIVERS'] -from dal import DAL, Field, SQLCustomType +from gluon.dal import DAL, Field, SQLCustomType from pydal.base import BaseAdapter from pydal.drivers import DRIVERS from pydal.objects import Table, Query, Set, Expression, Row, Rows diff --git a/gluon/tests/test_appadmin.py b/gluon/tests/test_appadmin.py index c47ac54f..9d7e0493 100644 --- a/gluon/tests/test_appadmin.py +++ b/gluon/tests/test_appadmin.py @@ -8,11 +8,6 @@ from __future__ import print_function import os import sys import unittest -import json - -from .fix_path import fix_sys_path - -fix_sys_path(__file__) from gluon.compileapp import run_controller_in, run_view_in @@ -165,6 +160,3 @@ class TestAppAdmin(unittest.TestCase): request._vars = data self.assertRaises(HTTP, self.run_function) - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_cache.py b/gluon/tests/test_cache.py index 47e11d34..4fcda0fb 100644 --- a/gluon/tests/test_cache.py +++ b/gluon/tests/test_cache.py @@ -6,10 +6,6 @@ """ import os import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) - from gluon.storage import Storage from gluon.cache import CacheInRam, CacheOnDisk, Cache @@ -147,8 +143,3 @@ class TestCache(unittest.TestCase): db.t_a.drop() db.close() - -if __name__ == '__main__': - setUpModule() # pre-python-2.7 - unittest.main() - tearDownModule() diff --git a/gluon/tests/test_compileapp.py b/gluon/tests/test_compileapp.py index 956c28a4..95645012 100644 --- a/gluon/tests/test_compileapp.py +++ b/gluon/tests/test_compileapp.py @@ -4,19 +4,20 @@ """ Unit tests for utils.py """ import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) +import os +import shutil 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, app_uninstall +from gluon.admin import app_compile, app_create, app_cleanup, check_new_version +from gluon.admin import app_uninstall from gluon.main import global_settings -import os, shutil + WEB2PY_VERSION_URL = "http://web2py.com/examples/default/version" + class TestPack(unittest.TestCase): """ Tests the compileapp.py module """ @@ -55,6 +56,3 @@ class TestPack(unittest.TestCase): self.assertEqual(app_uninstall(new_app, request), True) self.assertNotEqual(check_new_version(global_settings.web2py_version, WEB2PY_VERSION_URL), -1) return - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_contenttype.py b/gluon/tests/test_contenttype.py index 1a476a62..cb71a8d5 100644 --- a/gluon/tests/test_contenttype.py +++ b/gluon/tests/test_contenttype.py @@ -6,9 +6,7 @@ """ import unittest -from .fix_path import fix_sys_path -fix_sys_path(__file__) from gluon.contenttype import contenttype from gluon._compat import iteritems @@ -37,7 +35,3 @@ class TestContentType(unittest.TestCase): # test without dot extension rtn = contenttype('png') self.assertEqual(rtn, 'text/plain; charset=utf-8') - - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_contribs.py b/gluon/tests/test_contribs.py index 577056e4..633fa08b 100644 --- a/gluon/tests/test_contribs.py +++ b/gluon/tests/test_contribs.py @@ -5,9 +5,7 @@ import unittest import os -from .fix_path import fix_sys_path -fix_sys_path(__file__) from gluon._compat import to_bytes from gluon.storage import Storage from gluon.contrib import fpdf as fpdf @@ -67,6 +65,3 @@ class TestContribs(unittest.TestCase): self.assertEqual(myappconfig.take('config3.key2'), 2) current.request = {} - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_dal.py b/gluon/tests/test_dal.py index 4c7e0b24..d4e09df3 100644 --- a/gluon/tests/test_dal.py +++ b/gluon/tests/test_dal.py @@ -7,9 +7,6 @@ import sys import os import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) from gluon.dal import DAL, Field @@ -118,8 +115,3 @@ class TestDALAdapters(unittest.TestCase): os.environ["DB"] = "postgres:pg8000://postgres:@localhost/pydal" result = self._run_tests() self.assertTrue(result) - - -if __name__ == '__main__': - unittest.main() - tearDownModule() diff --git a/gluon/tests/test_fileutils.py b/gluon/tests/test_fileutils.py index cd405b00..5e408796 100644 --- a/gluon/tests/test_fileutils.py +++ b/gluon/tests/test_fileutils.py @@ -3,9 +3,6 @@ import unittest import datetime -from .fix_path import fix_sys_path - -fix_sys_path(__file__) from gluon.fileutils import parse_version @@ -25,7 +22,3 @@ class TestFileUtils(unittest.TestCase): # Semantic Beta rtn = parse_version('Version 2.14.1-beta+timestamp.2016.03.21.22.35.26') self.assertEqual(rtn, (2, 14, 1, 'beta', datetime.datetime(2016, 3, 21, 22, 35, 26))) - - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_globals.py b/gluon/tests/test_globals.py index d2336093..1ad85001 100644 --- a/gluon/tests/test_globals.py +++ b/gluon/tests/test_globals.py @@ -8,9 +8,6 @@ import re import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) from gluon.globals import Request, Response, Session from gluon import URL @@ -185,6 +182,3 @@ class testResponse(unittest.TestCase): current.session._fixup_before_save() cookie = str(current.response.cookies) self.assertTrue('httponly' not in cookie.lower()) - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_html.py b/gluon/tests/test_html.py index c861e511..d7a75517 100644 --- a/gluon/tests/test_html.py +++ b/gluon/tests/test_html.py @@ -6,9 +6,7 @@ """ import unittest -from .fix_path import fix_sys_path -fix_sys_path(__file__) from gluon.html import A, ASSIGNJS, B, BEAUTIFY, P, BODY, BR, BUTTON, CAT, CENTER, CODE, COL, COLGROUP, DIV, SPAN, URL, verifyURL from gluon.html import truncate_string, EM, FIELDSET, FORM, H1, H2, H3, H4, H5, H6, HEAD, HR, HTML, I, IFRAME, IMG, INPUT, EMBED @@ -706,7 +704,3 @@ class TestData(unittest.TestCase): def test_Adata(self): self.assertEqual(A('<>', data=dict(abc='', cde='standard'), _a='1', _b='2').xml(), b'<>') - - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_http.py b/gluon/tests/test_http.py index a344743b..7091b0a6 100644 --- a/gluon/tests/test_http.py +++ b/gluon/tests/test_http.py @@ -4,10 +4,6 @@ """Unit tests for http.py """ import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) - from gluon.http import HTTP, defined_status @@ -39,6 +35,3 @@ class TestHTTP(unittest.TestCase): gen_status_str(code, message)) # test wrong call detection - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_is_url.py b/gluon/tests/test_is_url.py index d75724c4..d4a3162b 100644 --- a/gluon/tests/test_is_url.py +++ b/gluon/tests/test_is_url.py @@ -5,10 +5,6 @@ Unit tests for IS_URL() """ import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) - from gluon.validators import IS_URL, IS_HTTP_URL, IS_GENERIC_URL from gluon.validators import unicode_to_ascii_authority @@ -694,6 +690,3 @@ class TestSimple(unittest.TestCase): # mode = 'generic' doesn't consider allowed_tlds rtn = IS_URL(mode='generic', allowed_tlds=['com', 'net', 'org'])('domain.ninja') self.assertEqual(rtn, ('domain.ninja', None)) - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_languages.py b/gluon/tests/test_languages.py index acc621ea..cb2fb6bc 100644 --- a/gluon/tests/test_languages.py +++ b/gluon/tests/test_languages.py @@ -10,9 +10,6 @@ import os import shutil import tempfile import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) from gluon import languages from gluon._compat import PY2 @@ -182,9 +179,3 @@ def index(): for key in ['hello', 'world', '%s %%{shop}', 'ahoy']: self.assertTrue(key in en_dict) self.assertTrue(key in pt_dict) - - - - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_old_doctests.py b/gluon/tests/test_old_doctests.py index 2da2ed3e..7fc74d54 100644 --- a/gluon/tests/test_old_doctests.py +++ b/gluon/tests/test_old_doctests.py @@ -1,18 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -""" Unit tests for old doctests in validators.py, utf8.py, html.py, - markmin2html.py. +""" Unit tests for old doctests in utf8.py, html.py, markmin2html.py. Don't abuse doctests, web2py > 2.4.5 will accept only unittests """ import sys import os import doctest import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) - def load_tests(loader, tests, ignore): diff --git a/gluon/tests/test_recfile.py b/gluon/tests/test_recfile.py index a2d711d3..03e36382 100644 --- a/gluon/tests/test_recfile.py +++ b/gluon/tests/test_recfile.py @@ -8,9 +8,7 @@ import unittest import os import shutil import uuid -from .fix_path import fix_sys_path -fix_sys_path(__file__) from gluon import recfile @@ -74,6 +72,3 @@ class TestRecfile(unittest.TestCase): self.assertRaises(IOError, recfile.remove, filename) self.assertRaises(IOError, recfile.open, filename, "r") - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_router.py b/gluon/tests/test_router.py index edec86cd..20b58358 100644 --- a/gluon/tests/test_router.py +++ b/gluon/tests/test_router.py @@ -3,25 +3,18 @@ """Unit tests for rewrite.py routers option""" from __future__ import print_function -import sys import os import unittest import tempfile import logging -if os.path.isdir('gluon'): - sys.path.insert(0,os.path.realpath('gluon')) # running from web2py base -else: - sys.path.insert(0,os.path.realpath('../../')) # running from gluon/tests/ - os.environ['web2py_path'] = os.path.realpath('../../') # for settings - from gluon.rewrite import load, filter_url, filter_err, get_effective_router, map_url_out from gluon.html import URL from gluon.fileutils import abspath from gluon.settings import global_settings from gluon.http import HTTP from gluon.storage import Storage -from gluon._compat import to_bytes, to_native, PY2 +from gluon._compat import to_bytes, PY2 logger = None oldcwd = None @@ -1518,8 +1511,3 @@ class TestRouter(unittest.TestCase): self.assertEqual(filter_url('http://welcome.com/welcome/admin/index', domain='welcome', out=True), "/welcome/admin") - -if __name__ == '__main__': - setUpModule() # pre-2.7 - unittest.main() - tearDownModule() diff --git a/gluon/tests/test_routes.py b/gluon/tests/test_routes.py index 16bb8a09..0fc5f2b8 100644 --- a/gluon/tests/test_routes.py +++ b/gluon/tests/test_routes.py @@ -9,12 +9,6 @@ import unittest import tempfile import logging -if os.path.isdir('gluon'): - sys.path.insert(0,os.path.realpath('gluon')) # running from web2py base -else: - sys.path.insert(0,os.path.realpath('../')) # running from gluon/tests/ - os.environ['web2py_path'] = os.path.realpath('../../') # for settings - from gluon.rewrite import load, filter_url, filter_err, get_effective_router, regex_filter_out, regex_select from gluon.html import URL from gluon.fileutils import abspath @@ -456,9 +450,3 @@ routes_out = [ self.assertEqual( filter_url('http://domain.com/index/a%20bc', env=True).request_uri, "/init/default/index/a bc") - - -if __name__ == '__main__': - setUpModule() # pre-2.7 - unittest.main() - tearDownModule() diff --git a/gluon/tests/test_scheduler.py b/gluon/tests/test_scheduler.py index 29cd877a..b473fe7b 100644 --- a/gluon/tests/test_scheduler.py +++ b/gluon/tests/test_scheduler.py @@ -10,9 +10,6 @@ import glob import datetime import sys -from .fix_path import fix_sys_path -fix_sys_path(__file__) - from gluon.storage import Storage from gluon.languages import translator from gluon.scheduler import JobGraph, Scheduler, CronParser diff --git a/gluon/tests/test_serializers.py b/gluon/tests/test_serializers.py index 0ae8dcb6..a7f2a44c 100644 --- a/gluon/tests/test_serializers.py +++ b/gluon/tests/test_serializers.py @@ -10,8 +10,6 @@ from .fix_path import fix_sys_path import datetime import decimal -fix_sys_path(__file__) - from gluon.serializers import * from gluon.storage import Storage # careful with the import path 'cause of isinstance() checks @@ -61,7 +59,3 @@ class TestSerializers(unittest.TestCase): # if unicode_keys is false, the standard behaviour is assumed base_load = loads_json(base_enc, unicode_keys=False) self.assertFalse(base == base_load) - - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_sqlhtml.py b/gluon/tests/test_sqlhtml.py index 39b3d8fc..d0b519a0 100644 --- a/gluon/tests/test_sqlhtml.py +++ b/gluon/tests/test_sqlhtml.py @@ -8,11 +8,7 @@ import os import sys import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) - -from sqlhtml import safe_int, SQLFORM, SQLTABLE +from gluon.sqlhtml import safe_int, SQLFORM, SQLTABLE DEFAULT_URI = os.getenv('DB', 'sqlite:memory') @@ -440,7 +436,3 @@ class TestSQLTABLE(unittest.TestCase): # def test_represented(self): # pass - - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_storage.py b/gluon/tests/test_storage.py index 48adce2e..6af22d19 100644 --- a/gluon/tests/test_storage.py +++ b/gluon/tests/test_storage.py @@ -4,9 +4,6 @@ """ Unit tests for storage.py """ import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) from gluon.storage import Storage, StorageList, List from gluon.http import HTTP @@ -152,7 +149,3 @@ class TestList(unittest.TestCase): a = List((1, 2, 3)) self.assertEqual(a[0], 1) self.assertEqual(a[::-1], [3, 2, 1]) - - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_template.py b/gluon/tests/test_template.py index 47ac8d44..9d21d775 100644 --- a/gluon/tests/test_template.py +++ b/gluon/tests/test_template.py @@ -5,9 +5,6 @@ """ import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) from gluon import template from gluon.template import render @@ -136,7 +133,3 @@ class TestTemplate(unittest.TestCase): render(filename=pjoin('views', 'default', 'noescape.html'), context={'NOESCAPE': template.NOESCAPE}), '') - - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_tools.py b/gluon/tests/test_tools.py index 91a9de6d..1fdf80f1 100644 --- a/gluon/tests/test_tools.py +++ b/gluon/tests/test_tools.py @@ -12,10 +12,6 @@ import smtplib import datetime import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) - DEFAULT_URI = os.getenv('DB', 'sqlite:memory') from gluon.dal import DAL, Field @@ -1362,6 +1358,3 @@ class TestExpose(unittest.TestCase): with self.assertRaises(HTTP): self.make_expose(base='inside', show='link_to_file3') - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_utils.py b/gluon/tests/test_utils.py index fde8d54f..8b94844f 100644 --- a/gluon/tests/test_utils.py +++ b/gluon/tests/test_utils.py @@ -4,17 +4,12 @@ """ Unit tests for utils.py """ import unittest -from .fix_path import fix_sys_path - -fix_sys_path(__file__) +import pickle +from hashlib import md5 from gluon.utils import md5_hash, compare, is_valid_ip_address, web2py_uuid - -import pickle -import hashlib import gluon.utils -from hashlib import md5, sha1, sha224, sha256, sha384, sha512 -from gluon.utils import simple_hash, get_digest, secure_dumps, secure_loads, basestring +from gluon.utils import simple_hash, get_digest, secure_dumps, secure_loads class TestUtils(unittest.TestCase): @@ -182,7 +177,3 @@ class TestUtils(unittest.TestCase): # TODO: def test_is_loopback_ip_address(self): # TODO: def test_getipaddrinfo(self): - - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_validators.py b/gluon/tests/test_validators.py index 19a18e16..c98b4c26 100644 --- a/gluon/tests/test_validators.py +++ b/gluon/tests/test_validators.py @@ -7,10 +7,6 @@ import unittest import datetime import decimal import re -from .fix_path import fix_sys_path - -fix_sys_path(__file__) - from gluon.validators import * from gluon._compat import PY2, to_bytes @@ -1122,7 +1118,3 @@ this is the content of the fake file self.assertEqual(rtn, ('2001::8ffa:fe22:b3af', None)) rtn = IS_IPADDRESS(subnets='invalidsubnet')('2001::8ffa:fe22:b3af') self.assertEqual(rtn, ('2001::8ffa:fe22:b3af', 'invalid subnet provided')) - - -if __name__ == '__main__': - unittest.main() diff --git a/gluon/tests/test_web.py b/gluon/tests/test_web.py index f7e9ddf3..4a3ef3bf 100644 --- a/gluon/tests/test_web.py +++ b/gluon/tests/test_web.py @@ -9,11 +9,8 @@ import os import unittest import subprocess import time -import signal -from .fix_path import fix_sys_path -fix_sys_path(__file__) from gluon.contrib.webclient import WebClient from gluon._compat import urllib2, PY2 @@ -32,7 +29,7 @@ def startwebserver(): break path = os.path.abspath(os.path.join(path, '..')) web2py_exec = os.path.join(path, 'web2py.py') - webserverprocess = subprocess.Popen([sys.executable, web2py_exec, '-a', 'testpass']) + webserverprocess = subprocess.Popen([sys.executable, web2py_exec, '-a', 'testpass']) print('Sleeping before web2py starts...') for a in range(1, 11): time.sleep(1) @@ -141,7 +138,3 @@ class TestWeb(LiveTest): # check internal server error returned (issue 153) assert(s.status == 500) assert(s.text == xml_response) - - -if __name__ == '__main__': - unittest.main()