From db701ffea868348f58fbc458a5c303d5ed90931b Mon Sep 17 00:00:00 2001 From: Hardirc Date: Sat, 2 Apr 2016 17:09:28 -0400 Subject: [PATCH] correct unproperly generated SQLFORM methods and basic tests --- gluon/tests/test_sqlhtml.py | 330 +++++++++++++----------------------- 1 file changed, 121 insertions(+), 209 deletions(-) diff --git a/gluon/tests/test_sqlhtml.py b/gluon/tests/test_sqlhtml.py index 40d3e972..a7d2a738 100644 --- a/gluon/tests/test_sqlhtml.py +++ b/gluon/tests/test_sqlhtml.py @@ -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(), '
') + + # 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(), '
') + + # 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(), '
1 records found
IdFirst nameLast nameE-mailUsername
1BartSimpsonuser1@test.comuser1 View
') + + def test_smartgrid(self): + smartgrid_form = SQLFORM.smartgrid(self.db.auth_user) + self.assertEqual(smartgrid_form.xml(), '
1 records found
') + + +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(), '
auth_user.idauth_user.first_nameauth_user.last_nameauth_user.emailauth_user.usernameauth_user.passwordauth_user.registration_keyauth_user.reset_password_keyauth_user.registration_id
1BartSimpsonuser1@test.comuser1password_123NoneNone
') # class TestExportClass(unittest.TestCase): @@ -524,4 +436,4 @@ class Test_safe_int(unittest.TestCase): if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()