Merge branch 'master' of github.com:web2py/web2py

This commit is contained in:
mdipierro
2013-08-25 19:27:46 -05:00
12 changed files with 405 additions and 73 deletions
+31 -5
View File
@@ -7,12 +7,38 @@
import sys import sys
import os import os
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else:
sys.path.append(os.path.realpath('../'))
import unittest 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 storage import Storage
from cache import CacheInRam, CacheOnDisk from cache import CacheInRam, CacheOnDisk
+29 -4
View File
@@ -6,10 +6,35 @@
import sys import sys
import os import os
import unittest import unittest
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon')) def fix_sys_path():
else: """
sys.path.append(os.path.realpath('../')) 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 from utils import md5_hash
import contrib.fpdf as fpdf import contrib.fpdf as fpdf
+56 -9
View File
@@ -8,17 +8,41 @@ import sys
import os import os
import glob import glob
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else:
sys.path.append(os.path.realpath('../'))
import unittest import unittest
import datetime import datetime
try: try:
import cStringIO as StringIO import cStringIO as StringIO
except: except:
from io import StringIO 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 from dal import DAL, Field, Table, SQLALL
#for travis-ci #for travis-ci
@@ -603,7 +627,7 @@ class TestComputedFields(unittest.TestCase):
self.assertEqual(db.tt[id].cc,'zx') self.assertEqual(db.tt[id].cc,'zx')
db.tt.drop() db.tt.drop()
db.commit() db.commit()
# test checking that a compute field can refer to earlier-defined computed fields # test checking that a compute field can refer to earlier-defined computed fields
db.define_table('tt', db.define_table('tt',
Field('aa'), Field('aa'),
@@ -612,10 +636,10 @@ class TestComputedFields(unittest.TestCase):
Field('dd',compute=lambda r: r.bb + r.cc)) Field('dd',compute=lambda r: r.bb + r.cc))
db.commit() db.commit()
id = db.tt.insert(aa="z") id = db.tt.insert(aa="z")
self.assertEqual(db.tt[id].dd,'xzx') self.assertEqual(db.tt[id].dd,'xzx')
db.tt.drop() db.tt.drop()
db.commit() db.commit()
class TestCommonFilters(unittest.TestCase): class TestCommonFilters(unittest.TestCase):
@@ -634,7 +658,7 @@ class TestCommonFilters(unittest.TestCase):
self.assertEqual(db(db.t1).count(),2) self.assertEqual(db(db.t1).count(),2)
q = db.t2.b==db.t1.id 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(db(q).count(),2)
self.assertEqual(len(db(db.t1).select(left=db.t2.on(q))),3) self.assertEqual(len(db(db.t1).select(left=db.t2.on(q))),3)
db.t2._common_filter = lambda q: db.t2.aa<6 db.t2._common_filter = lambda q: db.t2.aa<6
self.assertEqual(db(q).count(),1) self.assertEqual(db(q).count(),1)
@@ -788,6 +812,29 @@ class TestDALDictImportExport(unittest.TestCase):
db6.commit() 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()
+29 -5
View File
@@ -7,12 +7,36 @@
import sys import sys
import os import os
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else:
sys.path.append(os.path.realpath('../'))
import unittest 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 * from html import *
+37 -11
View File
@@ -6,10 +6,36 @@
import sys import sys
import os import os
import unittest import unittest
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else: def fix_sys_path():
sys.path.append(os.path.realpath('../')) """
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 from http import HTTP, defined_status
@@ -21,12 +47,12 @@ class TestHTTP(unittest.TestCase):
""" Tests http status code message """ """ Tests http status code message """
h = HTTP h = HTTP
def gen_status_str(code, message): def gen_status_str(code, message):
return str(code) + ' ' + str(message) return str(code) + ' ' + str(message)
message = '1423 This is a custom message' message = '1423 This is a custom message'
code = 1423 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)) gen_status_str(code, message))
# test predefined codes # test predefined codes
@@ -34,16 +60,16 @@ class TestHTTP(unittest.TestCase):
self.assertEqual( self.assertEqual(
str(h(code)), str(h(code)),
gen_status_str(code, defined_status[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(): 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)) gen_status_str(code, message))
# test wrong call detection # test wrong call detection
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
+31 -5
View File
@@ -6,12 +6,38 @@ Unit tests for IS_URL()
import sys import sys
import os import os
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else:
sys.path.append(os.path.realpath('../'))
import unittest 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, \ from validators import IS_URL, IS_HTTP_URL, IS_GENERIC_URL, \
unicode_to_ascii_authority unicode_to_ascii_authority
+31 -6
View File
@@ -7,16 +7,41 @@
import sys import sys
import os import os
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else:
sys.path.append(os.path.realpath('../'))
import unittest import unittest
import languages
import tempfile import tempfile
import threading import threading
import logging 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 from storage import Storage
try: try:
+32 -8
View File
@@ -7,14 +7,38 @@
""" """
import sys import sys
import os import os
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else:
sys.path.append(os.path.realpath('../'))
import unittest import unittest
import doctest 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): def load_tests(loader, tests, ignore):
tests.addTests( tests.addTests(
@@ -28,12 +52,12 @@ def load_tests(loader, tests, ignore):
tests.addTests( tests.addTests(
doctest.DocTestSuite('utf8') doctest.DocTestSuite('utf8')
) )
tests.addTests( tests.addTests(
doctest.DocTestSuite('contrib.markmin.markmin2html', doctest.DocTestSuite('contrib.markmin.markmin2html',
) )
) )
return tests return tests
if __name__ == '__main__': if __name__ == '__main__':
+29 -4
View File
@@ -6,10 +6,35 @@
import sys import sys
import os import os
import unittest import unittest
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else: def fix_sys_path():
sys.path.append(os.path.realpath('../')) """
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 storage import Storage
+30 -5
View File
@@ -6,12 +6,37 @@
import sys import sys
import os import os
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else:
sys.path.append(os.path.realpath('../'))
import unittest 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 from template import render
+29 -4
View File
@@ -6,10 +6,35 @@
import sys import sys
import os import os
import unittest import unittest
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else: def fix_sys_path():
sys.path.append(os.path.realpath('../')) """
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 from utils import md5_hash
+41 -7
View File
@@ -5,22 +5,56 @@
""" """
import sys import sys
import os import os
if os.path.isdir('gluon'):
sys.path.append(os.path.realpath('gluon'))
else:
sys.path.append(os.path.realpath('../'))
import unittest import unittest
import subprocess import subprocess
import time import time
import signal 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 from contrib.webclient import WebClient
webserverprocess = None webserverprocess = None
def startwebserver(): def startwebserver():
global webserverprocess 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...' print 'Sleeping before web2py starts...'
for a in range(1,11): for a in range(1,11):
time.sleep(1) time.sleep(1)
@@ -29,7 +63,7 @@ def startwebserver():
def terminate_process(pid): def terminate_process(pid):
#Taken from http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kill-a-subprocess #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() #we cannot use Popen.terminate()
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
import ctypes import ctypes