Author: ianb
Date: 2006-12-13 18:25:44 -0700 (Wed, 13 Dec 2006)
New Revision: 2129
Added:
FormEncode/trunk/tests/disabled_makeform.py
FormEncode/trunk/tests/disabled_sqlschema.py
Removed:
FormEncode/trunk/tests/test_makeform.py
FormEncode/trunk/tests/test_sqlschema.py
Log:
Disabled SQLObject-related tests
Copied: FormEncode/trunk/tests/disabled_makeform.py (from rev 2126,
FormEncode/trunk/tests/test_makeform.py)
===================================================================
--- FormEncode/trunk/tests/disabled_makeform.py (rev 0)
+++ FormEncode/trunk/tests/disabled_makeform.py 2006-12-14 01:25:44 UTC (rev
2129)
@@ -0,0 +1,70 @@
+# @@: Note, this is an experimental (TDD) test
+from sqlobject import *
+from formencode.formgen import makeform
+from formencode.fields import Context
+from formencode.doctest_xml_compare import xml_compare, make_xml
+from formencode import sqlformgen
+
+sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
+
+CONTEXT = Context()
+CONTEXT.secret = 'foo'
+
+def printer(s):
+ print s
+
+def xcmp(a, b):
+ try:
+ a = '<xml>%s</xml>' % a
+ xml_a = make_xml(a)
+ except:
+ print prxml(a)
+ raise
+ try:
+ b = '<xml>%s</xml>' % b
+ xml_b = make_xml(b)
+ except:
+ print prxml(b)
+ raise
+ prxml(a)
+ prxml(b)
+ assert xml_compare(xml_a, xml_b, reporter=printer)
+
+def prxml(xml):
+ for lineno, line in enumerate(xml.splitlines()):
+ print '%2i %s' % (lineno+1, line)
+
+class SimpleForm(SQLObject):
+
+ name = StringCol()
+ address = StringCol()
+ city = StringCol()
+
+SimpleForm.createTable()
+
+def test_simple():
+ f, v = makeform(SimpleForm, CONTEXT)
+ yield (xcmp, f(requires_label=True).render(CONTEXT), """
+ name: <input type="text" name="name" /> <br />
+ address: <input type="text" name="address" /> <br />
+ city: <input type="text" name="city" /> <br />
+ """)
+
+ f.name = 'simp'
+
+ yield (xcmp, f(requires_label=True).render(CONTEXT), """
+ name: <input type="text" name="simp.name" /> <br />
+ address: <input type="text" name="simp.address" /> <br />
+ city: <input type="text" name="simp.city" /> <br />
+ """)
+
+ # This test isn't really ready, so we'll skip
+ return
+ s = SimpleForm(name='Tom', address='123', city='Chicago')
+ f, v = makeform(s, CONTEXT)
+ yield (xcmp, f(requires_label=True).render(CONTEXT), """
+ name: <input type="text" name="name" value="Tom" /> <br />
+ address: <input type="text" name="address" value="123" /> <br />
+ city: <input type="text" name="city" value="Chicago" /> <br />
+ """)
+
Copied: FormEncode/trunk/tests/disabled_sqlschema.py (from rev 2126,
FormEncode/trunk/tests/test_sqlschema.py)
===================================================================
--- FormEncode/trunk/tests/disabled_sqlschema.py
(rev 0)
+++ FormEncode/trunk/tests/disabled_sqlschema.py 2006-12-14 01:25:44 UTC
(rev 2129)
@@ -0,0 +1,108 @@
+from sqlobject import *
+from formencode.sqlschema import *
+from formencode import validators
+from datetime import datetime, date
+
+def setup_module(module):
+ """Disable i18n translation
+ """
+ def notranslation(s): return s
+ import __builtin__
+ __builtin__._ = notranslation
+
+
+
+def teardown_module(module):
+ """Remove translation function
+ """
+ import __builtin__
+ del __builtin__._
+
+
+sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
+
+class EventObject(SQLObject):
+
+ name = StringCol(alternateID=True)
+ date = DateCol(notNull=True)
+ description = StringCol()
+
+EventObject.createTable()
+
+class EventObjectSchema(SQLSchema):
+
+ wrap = EventObject
+ # All other columns are inherited...
+ description = validators.String(strip=True, max=1024, if_empty=None)
+ date = validators.DateConverter(if_empty=None)
+
+def get_error(input, schema):
+ try:
+ result = schema.to_python(input)
+ assert 0, (
+ "Got %r from %r instead of an Invalid exception"
+ % (result, input))
+ except validators.Invalid, e:
+ return e
+
+def test_validate():
+ input = dict(name='test1', date='11/10/2010')
+ res = get_error(input, EventObjectSchema())
+ assert str(res) == 'description: Missing value'
+ input['description'] = ' test '
+ obj = EventObjectSchema().to_python(input)
+ assert isinstance(obj, EventObject)
+ assert obj.name == 'test1'
+ assert obj.date == date(2010, 11, 10)
+ assert obj.description == 'test'
+
+
+def test_update():
+ obj = EventObject(name='foobar', date=date(2020, 10, 1),
+ description=None)
+ input = dict(id=obj.id, date=None)
+ objschema = EventObjectSchema(wrap=obj)
+ assert str(get_error(input, objschema)) == 'date: You may not provide None
for that value'
+ input = dict(id=obj.id, name='test2')
+ print str(objschema.to_python(input))
+ assert objschema.to_python(input) is obj
+ assert obj.name == 'test2'
+
+def test_defaults():
+ res = EventObjectSchema().from_python(None)
+ assert res == dict(date=None, description='')
+ obj = EventObject(name='foobar2', date=date(2020, 10, 1),
+ description=None)
+ res = EventObjectSchema(wrap=obj).from_python(None)
+ assert res == dict(id=obj.id, date='10/01/2020',
+ name='foobar2', description='')
+ obj2 = EventObject(name='bar', date=date(2002, 10, 1),
+ description='foobarish')
+ # @@: Should this give an error?
+ res = EventObjectSchema(wrap=obj).from_python(obj2)
+ assert res == dict(id=obj2.id, date='10/01/2002',
+ name='bar', description='foobarish')
+ res2 = EventObjectSchema().from_python(obj2)
+ assert res2 == res
+
+def test_sign():
+ obj = EventObject(name='signer', date=date(2020, 10, 1),
+ description=None)
+ s = EventObjectSchema(sign_id=True, secret='bar')
+ res = s.from_python(obj)
+ assert res['id'] != str(obj)
+ res['name'] = 'signer_updated'
+ obj_up = s.to_python(res)
+ assert obj_up is obj
+ assert obj_up.name == 'signer_updated'
+ res2 = s.from_python(obj)
+ assert res['id'] != res2['id']
+ # Futz up the signature:
+ print 'before', res2['id'], res2['id'].split()[0].decode('base64')
+ res2['id'] = res2['id'][:2]+'XXX'+res2['id'][5:]
+ print 'after ', res2['id'], res2['id'].split()[0].decode('base64')
+ try:
+ s.to_python(res2)
+ assert 0
+ except validators.Invalid, e:
+ assert str(e) == 'Signature is not correct'
Deleted: FormEncode/trunk/tests/test_makeform.py
===================================================================
--- FormEncode/trunk/tests/test_makeform.py 2006-12-11 15:55:15 UTC (rev
2128)
+++ FormEncode/trunk/tests/test_makeform.py 2006-12-14 01:25:44 UTC (rev
2129)
@@ -1,70 +0,0 @@
-# @@: Note, this is an experimental (TDD) test
-from sqlobject import *
-from formencode.formgen import makeform
-from formencode.fields import Context
-from formencode.doctest_xml_compare import xml_compare, make_xml
-from formencode import sqlformgen
-
-sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
-
-CONTEXT = Context()
-CONTEXT.secret = 'foo'
-
-def printer(s):
- print s
-
-def xcmp(a, b):
- try:
- a = '<xml>%s</xml>' % a
- xml_a = make_xml(a)
- except:
- print prxml(a)
- raise
- try:
- b = '<xml>%s</xml>' % b
- xml_b = make_xml(b)
- except:
- print prxml(b)
- raise
- prxml(a)
- prxml(b)
- assert xml_compare(xml_a, xml_b, reporter=printer)
-
-def prxml(xml):
- for lineno, line in enumerate(xml.splitlines()):
- print '%2i %s' % (lineno+1, line)
-
-class SimpleForm(SQLObject):
-
- name = StringCol()
- address = StringCol()
- city = StringCol()
-
-SimpleForm.createTable()
-
-def test_simple():
- f, v = makeform(SimpleForm, CONTEXT)
- yield (xcmp, f(requires_label=True).render(CONTEXT), """
- name: <input type="text" name="name" /> <br />
- address: <input type="text" name="address" /> <br />
- city: <input type="text" name="city" /> <br />
- """)
-
- f.name = 'simp'
-
- yield (xcmp, f(requires_label=True).render(CONTEXT), """
- name: <input type="text" name="simp.name" /> <br />
- address: <input type="text" name="simp.address" /> <br />
- city: <input type="text" name="simp.city" /> <br />
- """)
-
- # This test isn't really ready, so we'll skip
- return
- s = SimpleForm(name='Tom', address='123', city='Chicago')
- f, v = makeform(s, CONTEXT)
- yield (xcmp, f(requires_label=True).render(CONTEXT), """
- name: <input type="text" name="name" value="Tom" /> <br />
- address: <input type="text" name="address" value="123" /> <br />
- city: <input type="text" name="city" value="Chicago" /> <br />
- """)
-
Deleted: FormEncode/trunk/tests/test_sqlschema.py
===================================================================
--- FormEncode/trunk/tests/test_sqlschema.py 2006-12-11 15:55:15 UTC (rev
2128)
+++ FormEncode/trunk/tests/test_sqlschema.py 2006-12-14 01:25:44 UTC (rev
2129)
@@ -1,108 +0,0 @@
-from sqlobject import *
-from formencode.sqlschema import *
-from formencode import validators
-from datetime import datetime, date
-
-def setup_module(module):
- """Disable i18n translation
- """
- def notranslation(s): return s
- import __builtin__
- __builtin__._ = notranslation
-
-
-
-def teardown_module(module):
- """Remove translation function
- """
- import __builtin__
- del __builtin__._
-
-
-sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
-
-class EventObject(SQLObject):
-
- name = StringCol(alternateID=True)
- date = DateCol(notNull=True)
- description = StringCol()
-
-EventObject.createTable()
-
-class EventObjectSchema(SQLSchema):
-
- wrap = EventObject
- # All other columns are inherited...
- description = validators.String(strip=True, max=1024, if_empty=None)
- date = validators.DateConverter(if_empty=None)
-
-def get_error(input, schema):
- try:
- result = schema.to_python(input)
- assert 0, (
- "Got %r from %r instead of an Invalid exception"
- % (result, input))
- except validators.Invalid, e:
- return e
-
-def test_validate():
- input = dict(name='test1', date='11/10/2010')
- res = get_error(input, EventObjectSchema())
- assert str(res) == 'description: Missing value'
- input['description'] = ' test '
- obj = EventObjectSchema().to_python(input)
- assert isinstance(obj, EventObject)
- assert obj.name == 'test1'
- assert obj.date == date(2010, 11, 10)
- assert obj.description == 'test'
-
-
-def test_update():
- obj = EventObject(name='foobar', date=date(2020, 10, 1),
- description=None)
- input = dict(id=obj.id, date=None)
- objschema = EventObjectSchema(wrap=obj)
- assert str(get_error(input, objschema)) == 'date: You may not provide None
for that value'
- input = dict(id=obj.id, name='test2')
- print str(objschema.to_python(input))
- assert objschema.to_python(input) is obj
- assert obj.name == 'test2'
-
-def test_defaults():
- res = EventObjectSchema().from_python(None)
- assert res == dict(date=None, description='')
- obj = EventObject(name='foobar2', date=date(2020, 10, 1),
- description=None)
- res = EventObjectSchema(wrap=obj).from_python(None)
- assert res == dict(id=obj.id, date='10/01/2020',
- name='foobar2', description='')
- obj2 = EventObject(name='bar', date=date(2002, 10, 1),
- description='foobarish')
- # @@: Should this give an error?
- res = EventObjectSchema(wrap=obj).from_python(obj2)
- assert res == dict(id=obj2.id, date='10/01/2002',
- name='bar', description='foobarish')
- res2 = EventObjectSchema().from_python(obj2)
- assert res2 == res
-
-def test_sign():
- obj = EventObject(name='signer', date=date(2020, 10, 1),
- description=None)
- s = EventObjectSchema(sign_id=True, secret='bar')
- res = s.from_python(obj)
- assert res['id'] != str(obj)
- res['name'] = 'signer_updated'
- obj_up = s.to_python(res)
- assert obj_up is obj
- assert obj_up.name == 'signer_updated'
- res2 = s.from_python(obj)
- assert res['id'] != res2['id']
- # Futz up the signature:
- print 'before', res2['id'], res2['id'].split()[0].decode('base64')
- res2['id'] = res2['id'][:2]+'XXX'+res2['id'][5:]
- print 'after ', res2['id'], res2['id'].split()[0].decode('base64')
- try:
- s.to_python(res2)
- assert 0
- except validators.Invalid, e:
- assert str(e) == 'Signature is not correct'
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs