Merge pull request #1260 from BuhtigithuB/add-test-sqlform
SQLFORM() basic check
This commit is contained in:
commit
7a2316ec9a
1 file changed
+121
-209
+121
-209
@@ -15,7 +15,18 @@ from fix_path import fix_sys_path
|
||||
|
||||
fix_sys_path(__file__)
|
||||
|
||||
from sqlhtml import safe_int
|
||||
from sqlhtml import safe_int, SQLFORM, SQLTABLE
|
||||
|
||||
DEFAULT_URI = os.getenv('DB', 'sqlite:memory')
|
||||
|
||||
from gluon.dal import DAL, Field
|
||||
from pydal.objects import Table
|
||||
from tools import Auth, Mail
|
||||
from gluon.globals import Request, Response, Session
|
||||
from storage import Storage
|
||||
from languages import translator
|
||||
from gluon.http import HTTP
|
||||
from validators import *
|
||||
|
||||
# TODO: Create these test...
|
||||
|
||||
@@ -45,7 +56,6 @@ class Test_safe_int(unittest.TestCase):
|
||||
self.assertEqual(safe_int('1x'), 0)
|
||||
|
||||
|
||||
|
||||
# class Test_safe_float(unittest.TestCase):
|
||||
# def test_safe_float(self):
|
||||
# pass
|
||||
@@ -238,212 +248,114 @@ class Test_safe_int(unittest.TestCase):
|
||||
# pass
|
||||
|
||||
|
||||
# class TestSQLFORM(unittest.TestCase):
|
||||
# def test___add__(self):
|
||||
# pass
|
||||
|
||||
# def test___delitem__(self):
|
||||
# pass
|
||||
|
||||
# def test___getitem__(self):
|
||||
# pass
|
||||
|
||||
# def test___init__(self):
|
||||
# pass
|
||||
|
||||
# def test___len__(self):
|
||||
# pass
|
||||
|
||||
# def test___mul__(self):
|
||||
# pass
|
||||
|
||||
# def test___nonzero__(self):
|
||||
# pass
|
||||
|
||||
# def test___setitem__(self):
|
||||
# pass
|
||||
|
||||
# def test___str__(self):
|
||||
# pass
|
||||
|
||||
# def test__fixup(self):
|
||||
# pass
|
||||
|
||||
# def test__postprocessing(self):
|
||||
# pass
|
||||
|
||||
# def test__setnode(self):
|
||||
# pass
|
||||
|
||||
# def test__traverse(self):
|
||||
# pass
|
||||
|
||||
# def test__validate(self):
|
||||
# pass
|
||||
|
||||
# def test__wrap_components(self):
|
||||
# pass
|
||||
|
||||
# def test__xml(self):
|
||||
# pass
|
||||
|
||||
# def test_accepts(self):
|
||||
# pass
|
||||
|
||||
# def test_add_button(self):
|
||||
# pass
|
||||
|
||||
# def test_add_class(self):
|
||||
# pass
|
||||
|
||||
# def test_append(self):
|
||||
# pass
|
||||
|
||||
# def test_as_dict(self):
|
||||
# pass
|
||||
|
||||
# def test_as_json(self):
|
||||
# pass
|
||||
|
||||
# def test_as_xml(self):
|
||||
# pass
|
||||
|
||||
# def test_as_yaml(self):
|
||||
# pass
|
||||
|
||||
# def test_assert_status(self):
|
||||
# pass
|
||||
|
||||
# def test_createform(self):
|
||||
# pass
|
||||
|
||||
# def test_element(self):
|
||||
# pass
|
||||
|
||||
# def test_elements(self):
|
||||
# pass
|
||||
|
||||
# def test_flatten(self):
|
||||
# pass
|
||||
|
||||
# def test_get(self):
|
||||
# pass
|
||||
|
||||
# def test_hidden_fields(self):
|
||||
# pass
|
||||
|
||||
# def test_insert(self):
|
||||
# pass
|
||||
|
||||
# def test_process(self):
|
||||
# pass
|
||||
|
||||
# def test_remove_class(self):
|
||||
# pass
|
||||
|
||||
# def test_sibling(self):
|
||||
# pass
|
||||
|
||||
# def test_siblings(self):
|
||||
# pass
|
||||
|
||||
# def test_update(self):
|
||||
# pass
|
||||
|
||||
# def test_validate(self):
|
||||
# pass
|
||||
|
||||
# def test_xml(self):
|
||||
# pass
|
||||
|
||||
|
||||
# class TestSQLTABLE(unittest.TestCase):
|
||||
# def test___add__(self):
|
||||
# pass
|
||||
|
||||
# def test___delitem__(self):
|
||||
# pass
|
||||
|
||||
# def test___getitem__(self):
|
||||
# pass
|
||||
|
||||
# def test___init__(self):
|
||||
# pass
|
||||
|
||||
# def test___len__(self):
|
||||
# pass
|
||||
|
||||
# def test___mul__(self):
|
||||
# pass
|
||||
|
||||
# def test___nonzero__(self):
|
||||
# pass
|
||||
|
||||
# def test___setitem__(self):
|
||||
# pass
|
||||
|
||||
# def test___str__(self):
|
||||
# pass
|
||||
|
||||
# def test__fixup(self):
|
||||
# pass
|
||||
|
||||
# def test__postprocessing(self):
|
||||
# pass
|
||||
|
||||
# def test__setnode(self):
|
||||
# pass
|
||||
|
||||
# def test__traverse(self):
|
||||
# pass
|
||||
|
||||
# def test__validate(self):
|
||||
# pass
|
||||
|
||||
# def test__wrap_components(self):
|
||||
# pass
|
||||
|
||||
# def test__xml(self):
|
||||
# pass
|
||||
|
||||
# def test_add_class(self):
|
||||
# pass
|
||||
|
||||
# def test_append(self):
|
||||
# pass
|
||||
|
||||
# def test_element(self):
|
||||
# pass
|
||||
|
||||
# def test_elements(self):
|
||||
# pass
|
||||
|
||||
# def test_flatten(self):
|
||||
# pass
|
||||
|
||||
# def test_get(self):
|
||||
# pass
|
||||
|
||||
# def test_insert(self):
|
||||
# pass
|
||||
|
||||
# def test_remove_class(self):
|
||||
# pass
|
||||
|
||||
# def test_sibling(self):
|
||||
# pass
|
||||
|
||||
# def test_siblings(self):
|
||||
# pass
|
||||
|
||||
# def test_style(self):
|
||||
# pass
|
||||
|
||||
# def test_update(self):
|
||||
# pass
|
||||
|
||||
# def test_xml(self):
|
||||
# pass
|
||||
class TestSQLFORM(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
request = Request(env={})
|
||||
request.application = 'a'
|
||||
request.controller = 'c'
|
||||
request.function = 'f'
|
||||
request.folder = 'applications/admin'
|
||||
response = Response()
|
||||
session = Session()
|
||||
T = translator('', 'en')
|
||||
session.connect(request, response)
|
||||
from gluon.globals import current
|
||||
current.request = request
|
||||
current.response = response
|
||||
current.session = session
|
||||
current.T = T
|
||||
self.db = DAL(DEFAULT_URI, check_reserved=['all'])
|
||||
self.auth = Auth(self.db)
|
||||
self.auth.define_tables(username=True, signature=False)
|
||||
self.db.define_table('t0', Field('tt'), self.auth.signature)
|
||||
self.auth.enable_record_versioning(self.db)
|
||||
# Create a user
|
||||
self.db.auth_user.insert(first_name='Bart',
|
||||
last_name='Simpson',
|
||||
username='user1',
|
||||
email='user1@test.com',
|
||||
password='password_123',
|
||||
registration_key=None,
|
||||
registration_id=None)
|
||||
|
||||
self.db.commit()
|
||||
|
||||
def test_SQLFORM(self):
|
||||
form = SQLFORM(self.db.auth_user)
|
||||
self.assertEqual(form.xml(), '<form action="#" enctype="multipart/form-data" method="post"><table><tr id="auth_user_first_name__row"><td class="w2p_fl"><label class="" for="auth_user_first_name" id="auth_user_first_name__label">First name: </label></td><td class="w2p_fw"><input class="string" id="auth_user_first_name" name="first_name" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_last_name__row"><td class="w2p_fl"><label class="" for="auth_user_last_name" id="auth_user_last_name__label">Last name: </label></td><td class="w2p_fw"><input class="string" id="auth_user_last_name" name="last_name" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_email__row"><td class="w2p_fl"><label class="" for="auth_user_email" id="auth_user_email__label">E-mail: </label></td><td class="w2p_fw"><input class="string" id="auth_user_email" name="email" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_username__row"><td class="w2p_fl"><label class="" for="auth_user_username" id="auth_user_username__label">Username: </label></td><td class="w2p_fw"><input class="string" id="auth_user_username" name="username" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_password__row"><td class="w2p_fl"><label class="" for="auth_user_password" id="auth_user_password__label">Password: </label></td><td class="w2p_fw"><input class="password" id="auth_user_password" name="password" type="password" value="" /></td><td class="w2p_fc"></td></tr><tr id="submit_record__row"><td class="w2p_fl"></td><td class="w2p_fw"><input type="submit" value="Submit" /></td><td class="w2p_fc"></td></tr></table></form>')
|
||||
|
||||
# def test_assert_status(self):
|
||||
# pass
|
||||
|
||||
# def test_createform(self):
|
||||
# pass
|
||||
|
||||
# def test_accepts(self):
|
||||
# pass
|
||||
|
||||
# def test_dictform(self):
|
||||
# pass
|
||||
|
||||
# def test_smartdictform(self):
|
||||
# pass
|
||||
|
||||
def test_factory(self):
|
||||
factory_form = SQLFORM.factory(Field('field_one', 'string', IS_NOT_EMPTY()),
|
||||
Field('field_two', 'string'))
|
||||
self.assertEqual(factory_form.xml(), '<form action="#" enctype="multipart/form-data" method="post"><table><tr id="no_table_field_one__row"><td class="w2p_fl"><label class="" for="no_table_field_one" id="no_table_field_one__label">Field One: </label></td><td class="w2p_fw"><input class="string" id="no_table_field_one" name="field_one" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="no_table_field_two__row"><td class="w2p_fl"><label class="" for="no_table_field_two" id="no_table_field_two__label">Field Two: </label></td><td class="w2p_fw"><input class="string" id="no_table_field_two" name="field_two" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="submit_record__row"><td class="w2p_fl"></td><td class="w2p_fw"><input type="submit" value="Submit" /></td><td class="w2p_fc"></td></tr></table></form>')
|
||||
|
||||
# def test_build_query(self):
|
||||
# pass
|
||||
|
||||
# def test_search_menu(self):
|
||||
# pass
|
||||
|
||||
def test_grid(self):
|
||||
grid_form = SQLFORM.grid(self.db.auth_user)
|
||||
self.assertEqual(grid_form.xml(), '<div class="web2py_grid "><div class="web2py_console "><form action="/a/c/f" enctype="multipart/form-data" method="GET"><input class="form-control" id="w2p_keywords" name="keywords" onfocus="jQuery('#w2p_query_fields').change();jQuery('#w2p_query_panel').slideDown();" type="text" value="" /><input class="btn btn-default" type="submit" value="Search" /><input class="btn btn-default" onclick="jQuery('#w2p_keywords').val('');" type="submit" value="Clear" /></form><div id="w2p_query_panel" style="display:none;"><select class="form-control" id="w2p_query_fields" onchange="jQuery('.w2p_query_row').hide();jQuery('#w2p_field_'+jQuery('#w2p_query_fields').val().replace('.','-')).show();" style="float:left"><option value="auth_user.id">Id</option><option value="auth_user.first_name">First name</option><option value="auth_user.last_name">Last name</option><option value="auth_user.email">E-mail</option><option value="auth_user.username">Username</option></select><div class="w2p_query_row" id="w2p_field_auth_user-id" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="<"><</option><option value=">">></option><option value="<="><=</option><option value=">=">>=</option><option value="in">in</option><option value="not in">not in</option></select><input class="id form-control" id="w2p_value_auth_user-id" type="text" /><input class="btn btn-default" onclick="w2p_build_query('new','auth_user.id')" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query('and','auth_user.id')" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query('or','auth_user.id')" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery('#w2p_query_panel').slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-first_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="<"><</option><option value=">">></option><option value="<="><=</option><option value=">=">>=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-first_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query('new','auth_user.first_name')" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query('and','auth_user.first_name')" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query('or','auth_user.first_name')" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery('#w2p_query_panel').slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-last_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="<"><</option><option value=">">></option><option value="<="><=</option><option value=">=">>=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-last_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query('new','auth_user.last_name')" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query('and','auth_user.last_name')" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query('or','auth_user.last_name')" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery('#w2p_query_panel').slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-email" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="<"><</option><option value=">">></option><option value="<="><=</option><option value=">=">>=</option><option value="starts with">starts with</option><Line truncated
|
||||
|
||||
def test_smartgrid(self):
|
||||
smartgrid_form = SQLFORM.smartgrid(self.db.auth_user)
|
||||
self.assertEqual(smartgrid_form.xml(), '<div class="web2py_grid "><div class="web2py_breadcrumbs"><ul class=""><li class="active w2p_grid_breadcrumb_elem"><a href="/a/c/f/auth_user">Auth users</a></li></ul></div><div class="web2py_console "><form action="/a/c/f/auth_user" enctype="multipart/form-data" method="GET"><input class="form-control" id="w2p_keywords" name="keywords" onfocus="jQuery('#w2p_query_fields').change();jQuery('#w2p_query_panel').slideDown();" type="text" value="" /><input class="btn btn-default" type="submit" value="Search" /><input class="btn btn-default" onclick="jQuery('#w2p_keywords').val('');" type="submit" value="Clear" /></form><div id="w2p_query_panel" style="display:none;"><select class="form-control" id="w2p_query_fields" onchange="jQuery('.w2p_query_row').hide();jQuery('#w2p_field_'+jQuery('#w2p_query_fields').val().replace('.','-')).show();" style="float:left"><option value="auth_user.id">Id</option><option value="auth_user.first_name">First name</option><option value="auth_user.last_name">Last name</option><option value="auth_user.email">E-mail</option><option value="auth_user.username">Username</option></select><div class="w2p_query_row" id="w2p_field_auth_user-id" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="<"><</option><option value=">">></option><option value="<="><=</option><option value=">=">>=</option><option value="in">in</option><option value="not in">not in</option></select><input class="id form-control" id="w2p_value_auth_user-id" type="text" /><input class="btn btn-default" onclick="w2p_build_query('new','auth_user.id')" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query('and','auth_user.id')" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query('or','auth_user.id')" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery('#w2p_query_panel').slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-first_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="<"><</option><option value=">">></option><option value="<="><=</option><option value=">=">>=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-first_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query('new','auth_user.first_name')" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query('and','auth_user.first_name')" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query('or','auth_user.first_name')" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery('#w2p_query_panel').slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-last_name" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="<"><</option><option value=">">></option><option value="<="><=</option><option value=">=">>=</option><option value="starts with">starts with</option><option value="contains">contains</option><option value="in">in</option><option value="not in">not in</option></select><input class="string form-control" id="w2p_value_auth_user-last_name" type="text" /><input class="btn btn-default" onclick="w2p_build_query('new','auth_user.last_name')" title="Start building a new search" type="button" value="New Search" /><input class="btn btn-default" onclick="w2p_build_query('and','auth_user.last_name')" title="Add this to the search as an AND term" type="button" value="+ And" /><input class="btn btn-default" onclick="w2p_build_query('or','auth_user.last_name')" title="Add this to the search as an OR term" type="button" value="+ Or" /><input class="btn btn-default" onclick="jQuery('#w2p_query_panel').slideUp()" type="button" value="Close" /></div><div class="w2p_query_row" id="w2p_field_auth_user-email" style="display:none"><select class="form-control"><option value="=">=</option><option value="!=">!=</option><option value="<"><</oLine truncated
|
||||
|
||||
|
||||
class TestSQLTABLE(unittest.TestCase):
|
||||
def setUp(self):
|
||||
request = Request(env={})
|
||||
request.application = 'a'
|
||||
request.controller = 'c'
|
||||
request.function = 'f'
|
||||
request.folder = 'applications/admin'
|
||||
response = Response()
|
||||
session = Session()
|
||||
T = translator('', 'en')
|
||||
session.connect(request, response)
|
||||
from gluon.globals import current
|
||||
current.request = request
|
||||
current.response = response
|
||||
current.session = session
|
||||
current.T = T
|
||||
self.db = DAL(DEFAULT_URI, check_reserved=['all'])
|
||||
self.auth = Auth(self.db)
|
||||
self.auth.define_tables(username=True, signature=False)
|
||||
self.db.define_table('t0', Field('tt'), self.auth.signature)
|
||||
self.auth.enable_record_versioning(self.db)
|
||||
# Create a user
|
||||
self.db.auth_user.insert(first_name='Bart',
|
||||
last_name='Simpson',
|
||||
username='user1',
|
||||
email='user1@test.com',
|
||||
password='password_123',
|
||||
registration_key=None,
|
||||
registration_id=None)
|
||||
|
||||
self.db.commit()
|
||||
|
||||
def test_SQLTABLE(self):
|
||||
rows = self.db(self.db.auth_user.id > 0).select(self.db.auth_user.ALL)
|
||||
sqltable = SQLTABLE(rows)
|
||||
self.assertEqual(sqltable.xml(), '<table><thead><tr><th>auth_user.id</th><th>auth_user.first_name</th><th>auth_user.last_name</th><th>auth_user.email</th><th>auth_user.username</th><th>auth_user.password</th><th>auth_user.registration_key</th><th>auth_user.reset_password_key</th><th>auth_user.registration_id</th></tr></thead><tbody><tr class="w2p_odd odd"><td>1</td><td>Bart</td><td>Simpson</td><td>user1@test.com</td><td>user1</td><td>password_123</td><td>None</td><td></td><td>None</td></tr></tbody></table>')
|
||||
|
||||
|
||||
# class TestExportClass(unittest.TestCase):
|
||||
@@ -524,4 +436,4 @@ class Test_safe_int(unittest.TestCase):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user