first step towards dropping sys.path dance

This commit is contained in:
niphlod
2016-08-29 23:01:22 +02:00
parent 326335c3cd
commit 1bf499e3be
28 changed files with 22 additions and 194 deletions
+4 -2
View File
@@ -4,6 +4,8 @@
- py3.5 syntax compatible (see #1353 for details) - py3.5 syntax compatible (see #1353 for details)
- dropped web shell from admin - dropped web shell from admin
- scheduler new feature: you can now specify intervals with cron - 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 ## 2.14.6
@@ -12,7 +14,7 @@
- Fixed some newly discovered security issues in admin: - Fixed some newly discovered security issues in admin:
CSRF vulnerability in admin that allows disabling apps CSRF vulnerability in admin that allows disabling apps
Brute force password attack vulnerability in admin Brute force password attack vulnerability in admin
(thanks Narendra and Leonel) (thanks Narendra and Leonel)
## 2.14.1-5 ## 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 - Added Portuguese, Catalan, and Burmese translations
- Allow map_hyphen to work for application names, thanks Tim Nyborg - Allow map_hyphen to work for application names, thanks Tim Nyborg
- New module appconfig.py, thanks Niphlod - 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 - Many bug fixes
+4 -2
View File
@@ -16,8 +16,10 @@ __all__ = ['A', 'B', 'BEAUTIFY', 'BODY', 'BR', 'CAT', 'CENTER', 'CLEANUP', 'CODE
import os import os
import sys import sys
try: try:
sys.path.insert(1,os.path.join( pydalpath = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "packages", "dal")) os.path.dirname(os.path.abspath(__file__)), "packages", "dal")
if pydalpath not in sys.path:
sys.path.append(pydalpath)
import pydal import pydal
sys.modules['pydal'] = pydal sys.modules['pydal'] = pydal
except ImportError: except ImportError:
+1 -1
View File
@@ -12,7 +12,7 @@ Just for backward compatibility
""" """
__all__ = ['DAL', 'Field', 'DRIVERS'] __all__ = ['DAL', 'Field', 'DRIVERS']
from dal import DAL, Field, SQLCustomType from gluon.dal import DAL, Field, SQLCustomType
from pydal.base import BaseAdapter from pydal.base import BaseAdapter
from pydal.drivers import DRIVERS from pydal.drivers import DRIVERS
from pydal.objects import Table, Query, Set, Expression, Row, Rows from pydal.objects import Table, Query, Set, Expression, Row, Rows
-8
View File
@@ -8,11 +8,6 @@ from __future__ import print_function
import os import os
import sys import sys
import unittest 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 from gluon.compileapp import run_controller_in, run_view_in
@@ -165,6 +160,3 @@ class TestAppAdmin(unittest.TestCase):
request._vars = data request._vars = data
self.assertRaises(HTTP, self.run_function) self.assertRaises(HTTP, self.run_function)
if __name__ == '__main__':
unittest.main()
-9
View File
@@ -6,10 +6,6 @@
""" """
import os import os
import unittest import unittest
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon.storage import Storage from gluon.storage import Storage
from gluon.cache import CacheInRam, CacheOnDisk, Cache from gluon.cache import CacheInRam, CacheOnDisk, Cache
@@ -147,8 +143,3 @@ class TestCache(unittest.TestCase):
db.t_a.drop() db.t_a.drop()
db.close() db.close()
if __name__ == '__main__':
setUpModule() # pre-python-2.7
unittest.main()
tearDownModule()
+6 -8
View File
@@ -4,19 +4,20 @@
""" Unit tests for utils.py """ """ Unit tests for utils.py """
import unittest import unittest
from .fix_path import fix_sys_path import os
import shutil
fix_sys_path(__file__)
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.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, 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 from gluon.main import global_settings
import os, shutil
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 """
@@ -55,6 +56,3 @@ class TestPack(unittest.TestCase):
self.assertEqual(app_uninstall(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) self.assertNotEqual(check_new_version(global_settings.web2py_version, WEB2PY_VERSION_URL), -1)
return return
if __name__ == '__main__':
unittest.main()
-6
View File
@@ -6,9 +6,7 @@
""" """
import unittest import unittest
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon.contenttype import contenttype from gluon.contenttype import contenttype
from gluon._compat import iteritems from gluon._compat import iteritems
@@ -37,7 +35,3 @@ class TestContentType(unittest.TestCase):
# test without dot extension # test without dot extension
rtn = contenttype('png') rtn = contenttype('png')
self.assertEqual(rtn, 'text/plain; charset=utf-8') self.assertEqual(rtn, 'text/plain; charset=utf-8')
if __name__ == '__main__':
unittest.main()
-5
View File
@@ -5,9 +5,7 @@
import unittest import unittest
import os import os
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon._compat import to_bytes from gluon._compat import to_bytes
from gluon.storage import Storage from gluon.storage import Storage
from gluon.contrib import fpdf as fpdf from gluon.contrib import fpdf as fpdf
@@ -67,6 +65,3 @@ class TestContribs(unittest.TestCase):
self.assertEqual(myappconfig.take('config3.key2'), 2) self.assertEqual(myappconfig.take('config3.key2'), 2)
current.request = {} current.request = {}
if __name__ == '__main__':
unittest.main()
-8
View File
@@ -7,9 +7,6 @@
import sys import sys
import os import os
import unittest import unittest
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon.dal import DAL, Field from gluon.dal import DAL, Field
@@ -118,8 +115,3 @@ class TestDALAdapters(unittest.TestCase):
os.environ["DB"] = "postgres:pg8000://postgres:@localhost/pydal" os.environ["DB"] = "postgres:pg8000://postgres:@localhost/pydal"
result = self._run_tests() result = self._run_tests()
self.assertTrue(result) self.assertTrue(result)
if __name__ == '__main__':
unittest.main()
tearDownModule()
-7
View File
@@ -3,9 +3,6 @@
import unittest import unittest
import datetime import datetime
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon.fileutils import parse_version from gluon.fileutils import parse_version
@@ -25,7 +22,3 @@ class TestFileUtils(unittest.TestCase):
# Semantic Beta # Semantic Beta
rtn = parse_version('Version 2.14.1-beta+timestamp.2016.03.21.22.35.26') 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))) self.assertEqual(rtn, (2, 14, 1, 'beta', datetime.datetime(2016, 3, 21, 22, 35, 26)))
if __name__ == '__main__':
unittest.main()
-6
View File
@@ -8,9 +8,6 @@
import re import re
import unittest import unittest
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon.globals import Request, Response, Session from gluon.globals import Request, Response, Session
from gluon import URL from gluon import URL
@@ -185,6 +182,3 @@ class testResponse(unittest.TestCase):
current.session._fixup_before_save() current.session._fixup_before_save()
cookie = str(current.response.cookies) cookie = str(current.response.cookies)
self.assertTrue('httponly' not in cookie.lower()) self.assertTrue('httponly' not in cookie.lower())
if __name__ == '__main__':
unittest.main()
-6
View File
@@ -6,9 +6,7 @@
""" """
import unittest 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 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 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): def test_Adata(self):
self.assertEqual(A('<>', data=dict(abc='<def?asd>', cde='standard'), _a='1', _b='2').xml(), self.assertEqual(A('<>', data=dict(abc='<def?asd>', cde='standard'), _a='1', _b='2').xml(),
b'<a a="1" b="2" data-abc="&lt;def?asd&gt;" data-cde="standard">&lt;&gt;</a>') b'<a a="1" b="2" data-abc="&lt;def?asd&gt;" data-cde="standard">&lt;&gt;</a>')
if __name__ == '__main__':
unittest.main()
-7
View File
@@ -4,10 +4,6 @@
"""Unit tests for http.py """ """Unit tests for http.py """
import unittest import unittest
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon.http import HTTP, defined_status from gluon.http import HTTP, defined_status
@@ -39,6 +35,3 @@ class TestHTTP(unittest.TestCase):
gen_status_str(code, message)) gen_status_str(code, message))
# test wrong call detection # test wrong call detection
if __name__ == '__main__':
unittest.main()
-7
View File
@@ -5,10 +5,6 @@ Unit tests for IS_URL()
""" """
import unittest 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 IS_URL, IS_HTTP_URL, IS_GENERIC_URL
from gluon.validators import unicode_to_ascii_authority from gluon.validators import unicode_to_ascii_authority
@@ -694,6 +690,3 @@ class TestSimple(unittest.TestCase):
# mode = 'generic' doesn't consider allowed_tlds # mode = 'generic' doesn't consider allowed_tlds
rtn = IS_URL(mode='generic', allowed_tlds=['com', 'net', 'org'])('domain.ninja') rtn = IS_URL(mode='generic', allowed_tlds=['com', 'net', 'org'])('domain.ninja')
self.assertEqual(rtn, ('domain.ninja', None)) self.assertEqual(rtn, ('domain.ninja', None))
if __name__ == '__main__':
unittest.main()
-9
View File
@@ -10,9 +10,6 @@ import os
import shutil import shutil
import tempfile import tempfile
import unittest import unittest
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon import languages from gluon import languages
from gluon._compat import PY2 from gluon._compat import PY2
@@ -182,9 +179,3 @@ def index():
for key in ['hello', 'world', '%s %%{shop}', 'ahoy']: for key in ['hello', 'world', '%s %%{shop}', 'ahoy']:
self.assertTrue(key in en_dict) self.assertTrue(key in en_dict)
self.assertTrue(key in pt_dict) self.assertTrue(key in pt_dict)
if __name__ == '__main__':
unittest.main()
+1 -6
View File
@@ -1,18 +1,13 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" Unit tests for old doctests in validators.py, utf8.py, html.py, """ Unit tests for old doctests in utf8.py, html.py, markmin2html.py.
markmin2html.py.
Don't abuse doctests, web2py > 2.4.5 will accept only unittests Don't abuse doctests, web2py > 2.4.5 will accept only unittests
""" """
import sys import sys
import os import os
import doctest import doctest
import unittest import unittest
from .fix_path import fix_sys_path
fix_sys_path(__file__)
def load_tests(loader, tests, ignore): def load_tests(loader, tests, ignore):
-5
View File
@@ -8,9 +8,7 @@ import unittest
import os import os
import shutil import shutil
import uuid import uuid
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon import recfile from gluon import recfile
@@ -74,6 +72,3 @@ class TestRecfile(unittest.TestCase):
self.assertRaises(IOError, recfile.remove, filename) self.assertRaises(IOError, recfile.remove, filename)
self.assertRaises(IOError, recfile.open, filename, "r") self.assertRaises(IOError, recfile.open, filename, "r")
if __name__ == '__main__':
unittest.main()
+1 -13
View File
@@ -3,25 +3,18 @@
"""Unit tests for rewrite.py routers option""" """Unit tests for rewrite.py routers option"""
from __future__ import print_function from __future__ import print_function
import sys
import os import os
import unittest import unittest
import tempfile import tempfile
import logging 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.rewrite import load, filter_url, filter_err, get_effective_router, map_url_out
from gluon.html import URL from gluon.html import URL
from gluon.fileutils import abspath from gluon.fileutils import abspath
from gluon.settings import global_settings from gluon.settings import global_settings
from gluon.http import HTTP from gluon.http import HTTP
from gluon.storage import Storage from gluon.storage import Storage
from gluon._compat import to_bytes, to_native, PY2 from gluon._compat import to_bytes, PY2
logger = None logger = None
oldcwd = None oldcwd = None
@@ -1518,8 +1511,3 @@ class TestRouter(unittest.TestCase):
self.assertEqual(filter_url('http://welcome.com/welcome/admin/index', self.assertEqual(filter_url('http://welcome.com/welcome/admin/index',
domain='welcome', out=True), "/welcome/admin") domain='welcome', out=True), "/welcome/admin")
if __name__ == '__main__':
setUpModule() # pre-2.7
unittest.main()
tearDownModule()
-12
View File
@@ -9,12 +9,6 @@ import unittest
import tempfile import tempfile
import logging 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.rewrite import load, filter_url, filter_err, get_effective_router, regex_filter_out, regex_select
from gluon.html import URL from gluon.html import URL
from gluon.fileutils import abspath from gluon.fileutils import abspath
@@ -456,9 +450,3 @@ routes_out = [
self.assertEqual( self.assertEqual(
filter_url('http://domain.com/index/a%20bc', env=True).request_uri, filter_url('http://domain.com/index/a%20bc', env=True).request_uri,
"/init/default/index/a bc") "/init/default/index/a bc")
if __name__ == '__main__':
setUpModule() # pre-2.7
unittest.main()
tearDownModule()
-3
View File
@@ -10,9 +10,6 @@ import glob
import datetime import datetime
import sys import sys
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon.storage import Storage from gluon.storage import Storage
from gluon.languages import translator from gluon.languages import translator
from gluon.scheduler import JobGraph, Scheduler, CronParser from gluon.scheduler import JobGraph, Scheduler, CronParser
-6
View File
@@ -10,8 +10,6 @@ from .fix_path import fix_sys_path
import datetime import datetime
import decimal import decimal
fix_sys_path(__file__)
from gluon.serializers import * from gluon.serializers import *
from gluon.storage import Storage from gluon.storage import Storage
# careful with the import path 'cause of isinstance() checks # 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 # if unicode_keys is false, the standard behaviour is assumed
base_load = loads_json(base_enc, unicode_keys=False) base_load = loads_json(base_enc, unicode_keys=False)
self.assertFalse(base == base_load) self.assertFalse(base == base_load)
if __name__ == '__main__':
unittest.main()
+1 -9
View File
@@ -8,11 +8,7 @@ import os
import sys import sys
import unittest import unittest
from .fix_path import fix_sys_path from gluon.sqlhtml import safe_int, SQLFORM, SQLTABLE
fix_sys_path(__file__)
from sqlhtml import safe_int, SQLFORM, SQLTABLE
DEFAULT_URI = os.getenv('DB', 'sqlite:memory') DEFAULT_URI = os.getenv('DB', 'sqlite:memory')
@@ -440,7 +436,3 @@ class TestSQLTABLE(unittest.TestCase):
# def test_represented(self): # def test_represented(self):
# pass # pass
if __name__ == '__main__':
unittest.main()
-7
View File
@@ -4,9 +4,6 @@
""" Unit tests for storage.py """ """ Unit tests for storage.py """
import unittest import unittest
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon.storage import Storage, StorageList, List from gluon.storage import Storage, StorageList, List
from gluon.http import HTTP from gluon.http import HTTP
@@ -152,7 +149,3 @@ class TestList(unittest.TestCase):
a = List((1, 2, 3)) a = List((1, 2, 3))
self.assertEqual(a[0], 1) self.assertEqual(a[0], 1)
self.assertEqual(a[::-1], [3, 2, 1]) self.assertEqual(a[::-1], [3, 2, 1])
if __name__ == '__main__':
unittest.main()
-7
View File
@@ -5,9 +5,6 @@
""" """
import unittest import unittest
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon import template from gluon import template
from gluon.template import render from gluon.template import render
@@ -136,7 +133,3 @@ class TestTemplate(unittest.TestCase):
render(filename=pjoin('views', 'default', 'noescape.html'), render(filename=pjoin('views', 'default', 'noescape.html'),
context={'NOESCAPE': template.NOESCAPE}), context={'NOESCAPE': template.NOESCAPE}),
'<script></script>') '<script></script>')
if __name__ == '__main__':
unittest.main()
-7
View File
@@ -12,10 +12,6 @@ import smtplib
import datetime import datetime
import unittest import unittest
from .fix_path import fix_sys_path
fix_sys_path(__file__)
DEFAULT_URI = os.getenv('DB', 'sqlite:memory') DEFAULT_URI = os.getenv('DB', 'sqlite:memory')
from gluon.dal import DAL, Field from gluon.dal import DAL, Field
@@ -1362,6 +1358,3 @@ class TestExpose(unittest.TestCase):
with self.assertRaises(HTTP): with self.assertRaises(HTTP):
self.make_expose(base='inside', show='link_to_file3') self.make_expose(base='inside', show='link_to_file3')
if __name__ == '__main__':
unittest.main()
+3 -12
View File
@@ -4,17 +4,12 @@
""" Unit tests for utils.py """ """ Unit tests for utils.py """
import unittest import unittest
from .fix_path import fix_sys_path import pickle
from hashlib import md5
fix_sys_path(__file__)
from gluon.utils import md5_hash, compare, is_valid_ip_address, web2py_uuid from gluon.utils import md5_hash, compare, is_valid_ip_address, web2py_uuid
import pickle
import hashlib
import gluon.utils import gluon.utils
from hashlib import md5, sha1, sha224, sha256, sha384, sha512 from gluon.utils import simple_hash, get_digest, secure_dumps, secure_loads
from gluon.utils import simple_hash, get_digest, secure_dumps, secure_loads, basestring
class TestUtils(unittest.TestCase): class TestUtils(unittest.TestCase):
@@ -182,7 +177,3 @@ class TestUtils(unittest.TestCase):
# TODO: def test_is_loopback_ip_address(self): # TODO: def test_is_loopback_ip_address(self):
# TODO: def test_getipaddrinfo(self): # TODO: def test_getipaddrinfo(self):
if __name__ == '__main__':
unittest.main()
-8
View File
@@ -7,10 +7,6 @@ import unittest
import datetime import datetime
import decimal import decimal
import re import re
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon.validators import * from gluon.validators import *
from gluon._compat import PY2, to_bytes 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)) self.assertEqual(rtn, ('2001::8ffa:fe22:b3af', None))
rtn = IS_IPADDRESS(subnets='invalidsubnet')('2001::8ffa:fe22:b3af') rtn = IS_IPADDRESS(subnets='invalidsubnet')('2001::8ffa:fe22:b3af')
self.assertEqual(rtn, ('2001::8ffa:fe22:b3af', 'invalid subnet provided')) self.assertEqual(rtn, ('2001::8ffa:fe22:b3af', 'invalid subnet provided'))
if __name__ == '__main__':
unittest.main()
+1 -8
View File
@@ -9,11 +9,8 @@ import os
import unittest import unittest
import subprocess import subprocess
import time import time
import signal
from .fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon.contrib.webclient import WebClient from gluon.contrib.webclient import WebClient
from gluon._compat import urllib2, PY2 from gluon._compat import urllib2, PY2
@@ -32,7 +29,7 @@ def startwebserver():
break break
path = os.path.abspath(os.path.join(path, '..')) path = os.path.abspath(os.path.join(path, '..'))
web2py_exec = os.path.join(path, 'web2py.py') 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...') print('Sleeping before web2py starts...')
for a in range(1, 11): for a in range(1, 11):
time.sleep(1) time.sleep(1)
@@ -141,7 +138,3 @@ class TestWeb(LiveTest):
# check internal server error returned (issue 153) # check internal server error returned (issue 153)
assert(s.status == 500) assert(s.status == 500)
assert(s.text == xml_response) assert(s.text == xml_response)
if __name__ == '__main__':
unittest.main()