Merge branch 'master' of github.com:web2py/web2py
This commit is contained in:
@@ -7,12 +7,38 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
|
||||
from storage import Storage
|
||||
from cache import CacheInRam, CacheOnDisk
|
||||
|
||||
|
||||
@@ -6,10 +6,35 @@
|
||||
import sys
|
||||
import os
|
||||
import unittest
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
|
||||
from utils import md5_hash
|
||||
import contrib.fpdf as fpdf
|
||||
|
||||
@@ -8,17 +8,41 @@ import sys
|
||||
import os
|
||||
import glob
|
||||
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
import unittest
|
||||
import datetime
|
||||
try:
|
||||
import cStringIO as StringIO
|
||||
except:
|
||||
from io import StringIO
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
from dal import DAL, Field, Table, SQLALL
|
||||
|
||||
#for travis-ci
|
||||
@@ -603,7 +627,7 @@ class TestComputedFields(unittest.TestCase):
|
||||
self.assertEqual(db.tt[id].cc,'zx')
|
||||
db.tt.drop()
|
||||
db.commit()
|
||||
|
||||
|
||||
# test checking that a compute field can refer to earlier-defined computed fields
|
||||
db.define_table('tt',
|
||||
Field('aa'),
|
||||
@@ -612,10 +636,10 @@ class TestComputedFields(unittest.TestCase):
|
||||
Field('dd',compute=lambda r: r.bb + r.cc))
|
||||
db.commit()
|
||||
id = db.tt.insert(aa="z")
|
||||
self.assertEqual(db.tt[id].dd,'xzx')
|
||||
self.assertEqual(db.tt[id].dd,'xzx')
|
||||
db.tt.drop()
|
||||
db.commit()
|
||||
|
||||
|
||||
|
||||
class TestCommonFilters(unittest.TestCase):
|
||||
|
||||
@@ -634,7 +658,7 @@ class TestCommonFilters(unittest.TestCase):
|
||||
self.assertEqual(db(db.t1).count(),2)
|
||||
q = db.t2.b==db.t1.id
|
||||
self.assertEqual(db(q).count(),2)
|
||||
self.assertEqual(db(q).count(),2)
|
||||
self.assertEqual(db(q).count(),2)
|
||||
self.assertEqual(len(db(db.t1).select(left=db.t2.on(q))),3)
|
||||
db.t2._common_filter = lambda q: db.t2.aa<6
|
||||
self.assertEqual(db(q).count(),1)
|
||||
@@ -788,6 +812,29 @@ class TestDALDictImportExport(unittest.TestCase):
|
||||
db6.commit()
|
||||
|
||||
|
||||
class TestValidateAndInsert(unittest.TestCase):
|
||||
|
||||
def testRun(self):
|
||||
import datetime
|
||||
from gluon.validators import IS_INT_IN_RANGE
|
||||
db = DAL(DEFAULT_URI, check_reserved=['all'])
|
||||
db.define_table('val_and_insert',
|
||||
Field('aa'),
|
||||
Field('bb', 'integer',
|
||||
requires=IS_INT_IN_RANGE(1,5))
|
||||
)
|
||||
rtn = db.val_and_insert.validate_and_insert(aa='test1', bb=2)
|
||||
self.assertEqual(rtn.id, 1)
|
||||
#errors should be empty
|
||||
self.assertEqual(len(rtn.errors.keys()), 0)
|
||||
#this insert won't pass
|
||||
rtn = db.val_and_insert.validate_and_insert(bb="a")
|
||||
#the returned id should be None
|
||||
self.assertEqual(rtn.id, None)
|
||||
#an error message should be in rtn.errors.bb
|
||||
self.assertNotEqual(rtn.errors.bb, None)
|
||||
#cleanup table
|
||||
db.val_and_insert.drop()
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,12 +7,36 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
import unittest
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
from html import *
|
||||
|
||||
|
||||
|
||||
@@ -6,10 +6,36 @@
|
||||
import sys
|
||||
import os
|
||||
import unittest
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
|
||||
from http import HTTP, defined_status
|
||||
|
||||
@@ -21,12 +47,12 @@ class TestHTTP(unittest.TestCase):
|
||||
""" Tests http status code message """
|
||||
|
||||
h = HTTP
|
||||
|
||||
|
||||
def gen_status_str(code, message):
|
||||
return str(code) + ' ' + str(message)
|
||||
message = '1423 This is a custom message'
|
||||
code = 1423
|
||||
self.assertEqual(str(h(gen_status_str(code, message))),
|
||||
self.assertEqual(str(h(gen_status_str(code, message))),
|
||||
gen_status_str(code, message))
|
||||
|
||||
# test predefined codes
|
||||
@@ -34,16 +60,16 @@ class TestHTTP(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
str(h(code)),
|
||||
gen_status_str(code, defined_status[code]))
|
||||
|
||||
# test correct use of status_message
|
||||
|
||||
# test correct use of status_message
|
||||
for code in defined_status.keys():
|
||||
self.assertEqual(str(h(gen_status_str(code, message))),
|
||||
self.assertEqual(str(h(gen_status_str(code, message))),
|
||||
gen_status_str(code, message))
|
||||
|
||||
# test wrong call detection
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -6,12 +6,38 @@ Unit tests for IS_URL()
|
||||
|
||||
import sys
|
||||
import os
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
|
||||
from validators import IS_URL, IS_HTTP_URL, IS_GENERIC_URL, \
|
||||
unicode_to_ascii_authority
|
||||
|
||||
|
||||
@@ -7,16 +7,41 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
import unittest
|
||||
import languages
|
||||
import tempfile
|
||||
import threading
|
||||
import logging
|
||||
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
fix_sys_path()
|
||||
|
||||
|
||||
import languages
|
||||
from storage import Storage
|
||||
|
||||
try:
|
||||
|
||||
@@ -7,14 +7,38 @@
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
import unittest
|
||||
import doctest
|
||||
|
||||
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
def load_tests(loader, tests, ignore):
|
||||
|
||||
tests.addTests(
|
||||
@@ -28,12 +52,12 @@ def load_tests(loader, tests, ignore):
|
||||
tests.addTests(
|
||||
doctest.DocTestSuite('utf8')
|
||||
)
|
||||
|
||||
|
||||
tests.addTests(
|
||||
doctest.DocTestSuite('contrib.markmin.markmin2html',
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
return tests
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -6,10 +6,35 @@
|
||||
import sys
|
||||
import os
|
||||
import unittest
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
from storage import Storage
|
||||
|
||||
|
||||
@@ -6,12 +6,37 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
from template import render
|
||||
|
||||
|
||||
|
||||
@@ -6,10 +6,35 @@
|
||||
import sys
|
||||
import os
|
||||
import unittest
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
from utils import md5_hash
|
||||
|
||||
|
||||
@@ -5,22 +5,56 @@
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon'))
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../'))
|
||||
|
||||
import unittest
|
||||
import subprocess
|
||||
import time
|
||||
import signal
|
||||
|
||||
|
||||
def fix_sys_path():
|
||||
"""
|
||||
logic to have always the correct sys.path
|
||||
'', web2py/gluon, web2py/site-packages, web2py/ ...
|
||||
"""
|
||||
|
||||
def add_path_first(path):
|
||||
sys.path = [path] + [p for p in sys.path if (
|
||||
not p == path and not p == (path + '/'))]
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
break
|
||||
path = os.path.abspath(os.path.join(path, '..'))
|
||||
|
||||
paths = [path,
|
||||
os.path.abspath(os.path.join(path, 'site-packages')),
|
||||
os.path.abspath(os.path.join(path, 'gluon')),
|
||||
'']
|
||||
[add_path_first(path) for path in paths]
|
||||
|
||||
fix_sys_path()
|
||||
|
||||
from contrib.webclient import WebClient
|
||||
|
||||
webserverprocess = None
|
||||
|
||||
def startwebserver():
|
||||
global webserverprocess
|
||||
webserverprocess = subprocess.Popen([sys.executable, 'web2py.py', '-a', 'testpass'])
|
||||
path = path = os.path.dirname(os.path.abspath(__file__))
|
||||
if not os.path.isfile(os.path.join(path,'web2py.py')):
|
||||
i = 0
|
||||
while i<10:
|
||||
i += 1
|
||||
if os.path.exists(os.path.join(path,'web2py.py')):
|
||||
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'])
|
||||
print 'Sleeping before web2py starts...'
|
||||
for a in range(1,11):
|
||||
time.sleep(1)
|
||||
@@ -29,7 +63,7 @@ def startwebserver():
|
||||
|
||||
def terminate_process(pid):
|
||||
#Taken from http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kill-a-subprocess
|
||||
# all this shit is because we are stuck with Python 2.5 and \
|
||||
# all this **blah** is because we are stuck with Python 2.5 and \
|
||||
#we cannot use Popen.terminate()
|
||||
if sys.platform.startswith('win'):
|
||||
import ctypes
|
||||
|
||||
Reference in New Issue
Block a user