Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:smarty12:Python
python-pyramid_simpleform
pyramid_simpleform-git-7004f60f.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File pyramid_simpleform-git-7004f60f.patch of Package python-pyramid_simpleform
Index: b/pyramid_simpleform/__init__.py =================================================================== --- a/pyramid_simpleform/__init__.py +++ b/pyramid_simpleform/__init__.py @@ -2,7 +2,7 @@ from formencode import htmlfill from formencode import variabledecode from formencode import Invalid -from pyramid.i18n import get_localizer +from pyramid.i18n import get_localizer, TranslationStringFactory, TranslationString from pyramid.renderers import render class State(object): @@ -35,11 +35,26 @@ class State(object): def get(self, k, default=None): return getattr(self, k, default) +fe_tsf = TranslationStringFactory('FormEncode') -class Form(object): +def get_default_translate_fn(request): + pyramid_translate = get_localizer(request).translate + + def translate(s): + if not isinstance(s, TranslationString): + s = fe_tsf(s) + + return pyramid_translate(s) + + return translate + + +class Form(object): """ + Legacy class for validating FormEncode schemas and validators. + `request` : Pyramid request instance `schema` : FormEncode Schema class or instance @@ -91,16 +106,16 @@ class Form(object): self.state = self.default_state() if not hasattr(self.state, '_'): - self.state._ = get_localizer(self.request).translate + self.state._ = get_default_translate_fn(request) if defaults: self.data.update(defaults) if obj: - fields = self.schema.fields.keys() + self.validators.keys() + fields = self.schema.fields.keys() + self.validators.keys() for f in fields: if hasattr(obj, f): - self.data[f] = getattr(obj, f) + self.data[f] = getattr(obj, f) def is_error(self, field): """ @@ -130,7 +145,7 @@ class Form(object): errors = [errors] return errors - def validate(self): + def validate(self, force_validate=False, params=None): """ Runs validation and returns True/False whether form is valid. @@ -144,6 +159,10 @@ class Form(object): The errors and data values will be updated accordingly. + `force_validate` : will run validation regardless of request method. + + `params` : dict or MultiDict of params. By default + will use **request.POST** (if HTTP POST) or **request.params**. """ assert self.schema or self.validators, \ @@ -152,14 +171,16 @@ class Form(object): if self.is_validated: return not(self.errors) - if self.method and self.method != self.request.method: - return False - - if self.method == "POST": - params = self.request.POST - else: - params = self.request.params - + if not force_validate: + if self.method and self.method != self.request.method: + return False + + if params is None: + if self.method == "POST": + params = self.request.POST + else: + params = self.request.params + if self.variable_decode: decoded = variabledecode.variable_decode( params, self.dict_char, self.list_char) Index: b/pyramid_simpleform/renderers.py =================================================================== --- a/pyramid_simpleform/renderers.py +++ b/pyramid_simpleform/renderers.py @@ -2,114 +2,93 @@ from webhelpers.html import tags from webhelpers.html.builder import HTML -class FormRenderer(object): - """ - A simple form helper. Uses WebHelpers to render individual - form widgets: see the WebHelpers library for more information - on individual widgets. - """ - def __init__(self, form, csrf_field='_csrf'): +class Renderer(object): - self.form = form - self.data = self.form.data - self.csrf_field = csrf_field + def __init__(self, data, errors, id_prefix=None): + self.data = data + self.errors = errors + self.id_prefix = id_prefix - def value(self, name, default=None): - return self.data.get(name, default) + def get_sequence(self, name, min_entries=0): - def begin(self, url=None, **attrs): - """ - Creates the opening <form> tags. + data = self.value(name, []) + errors = self.errors.get(name, {}) - By default URL will be current path. - """ - url = url or self.form.request.path - multipart = attrs.pop('multipart', self.form.multipart) - return tags.form(url, multipart=multipart, **attrs) - - def end(self): - """ - Closes the form, i.e. outputs </form>. - """ - return tags.end_form() - - def csrf(self, name=None): - """ - Returns the CSRF hidden input. Creates new CSRF token - if none has been assigned yet. + return SequenceRenderer(name, data, errors, min_entries=min_entries) - The name of the hidden field is **_csrf** by default. - """ - name = name or self.csrf_field + def get_mapping(self, name): - token = self.form.request.session.get_csrf_token() - if token is None: - token = self.form.request.session.new_csrf_token() + data = self.value(name, {}) + errors = self.errors(name, []) - return self.hidden(name, value=token) - - def csrf_token(self, name=None): - """ - Convenience function. Returns CSRF hidden tag inside hidden DIV. - """ - return HTML.tag("div", self.csrf(name), style="display:none;") - - def hidden_tag(self, *names): - """ - Convenience for printing all hidden fields in a form inside a - hidden DIV. Will also render the CSRF hidden field. - - :versionadded: 0.4 - """ - inputs = [self.hidden(name) for name in names] - inputs.append(self.csrf()) - return HTML.tag("div", - tags.literal("".join(inputs)), - style="display:none;") + return MappingRenderer(name, data, errors) def text(self, name, value=None, id=None, **attrs): """ Outputs text input. """ - id = id or name - return tags.text(name, self.value(name, value), id, **attrs) + return tags.text( + name, + self.value(name, value), + self._get_id(id, name), + **attrs + ) def file(self, name, value=None, id=None, **attrs): """ Outputs file input. """ - id = id or name - return tags.file(name, self.value(name, value), id, **attrs) + return tags.file( + name, + self.value(name, value), + self._get_id(id, name), + **attrs + ) def hidden(self, name, value=None, id=None, **attrs): """ Outputs hidden input. """ - id = id or name - return tags.hidden(name, self.value(name, value), id, **attrs) + if value is None: + value = self.value(name) + + return tags.hidden( + name, + value, + self._get_id(id, name), + **attrs + ) def radio(self, name, value=None, checked=False, label=None, **attrs): """ Outputs radio input. """ - checked = self.data.get(name) == value or checked + checked = self.value(name) == value or checked return tags.radio(name, value, checked, label, **attrs) def submit(self, name, value=None, id=None, **attrs): """ Outputs submit button. """ - id = id or name - return tags.submit(name, self.value(name, value), id, **attrs) + return tags.submit( + name, + self.value(name, value), + self._get_id(id, name), + **attrs + ) def select(self, name, options, selected_value=None, id=None, **attrs): """ Outputs <select> element. """ - id = id or name - return tags.select(name, self.value(name, selected_value), - options, id, **attrs) + return tags.select( + name, + self.value(name, selected_value), + options, + self._get_id(id, name), + **attrs + ) def checkbox(self, name, value="1", checked=False, label=None, id=None, **attrs): @@ -117,28 +96,41 @@ class FormRenderer(object): Outputs checkbox input. """ - id = id or name - return tags.checkbox(name, value, self.value(name), label, id, **attrs) + return tags.checkbox( + name, + value, + self.value(name), + label, + self._get_id(id, name), + **attrs + ) def textarea(self, name, content="", id=None, **attrs): """ Outputs <textarea> element. """ - id = id or name - return tags.textarea(name, self.value(name, content), id, **attrs) + + return tags.textarea( + name, + self.value(name, content), + self._get_id(id, name), + **attrs + ) def password(self, name, value=None, id=None, **attrs): """ Outputs a password input. """ - id = id or name - return tags.password(name, self.value(name, value), id, **attrs) + return tags.password( + name, self.value(name, value), + self._get_id(id, name), + **attrs) def is_error(self, name): """ Shortcut for **self.form.is_error(name)** """ - return self.form.is_error(name) + return name in self.errors def errors_for(self, name): """ @@ -150,7 +142,7 @@ class FormRenderer(object): """ Shortcut for **self.form.all_errors()** """ - return self.form.all_errors() + return self.errors.values() def errorlist(self, name=None, **attrs): """ @@ -186,7 +178,155 @@ class FormRenderer(object): `label` : if **None**, uses the capitalized field name. """ if 'for_' not in attrs: - attrs['for_'] = name + for_ = name.lower() + if self.id_prefix: + for_ = self.id_prefix + for_ + attrs['for_'] = for_ + label = label or name.capitalize() return HTML.tag("label", label, **attrs) + def value(self, name, default=None): + return self.data.get(name, default) + + def _get_id(self, id, name): + if id is None: + id = name + if self.id_prefix: + id = self.id_prefix + id + return id + + +class FormRenderer(Renderer): + """ + A simple form helper. Uses WebHelpers to render individual + form widgets: see the WebHelpers library for more information + on individual widgets. + """ + + def __init__(self, form, csrf_field='_csrf', id_prefix=None): + + self.form = form + self.csrf_field = csrf_field + + super(FormRenderer, self).__init__( + self.form.data, + self.form.errors, + id_prefix, + ) + + + def begin(self, url=None, **attrs): + """ + Creates the opening <form> tags. + + By default URL will be current path. + """ + url = url or self.form.request.path + multipart = attrs.pop('multipart', self.form.multipart) + return tags.form(url, multipart=multipart, **attrs) + + def end(self): + """ + Closes the form, i.e. outputs </form>. + """ + return tags.end_form() + + def csrf(self, name=None): + """ + Returns the CSRF hidden input. Creates new CSRF token + if none has been assigned yet. + + The name of the hidden field is **_csrf** by default. + """ + name = name or self.csrf_field + + token = self.form.request.session.get_csrf_token() + if token is None: + token = self.form.request.session.new_csrf_token() + + return self.hidden(name, value=token) + + def csrf_token(self, name=None): + """ + Convenience function. Returns CSRF hidden tag inside hidden DIV. + """ + return HTML.tag("div", self.csrf(name), style="display:none;") + + def hidden_tag(self, *names): + """ + Convenience for printing all hidden fields in a form inside a + hidden DIV. Will also render the CSRF hidden field. + + :versionadded: 0.4 + """ + inputs = [self.hidden(name) for name in names] + inputs.append(self.csrf()) + return HTML.tag("div", + tags.literal("".join(inputs)), + style="display:none;") + + +class SequenceRenderer(Renderer): + + def __init__(self, name, data, errors, id_prefix=None, min_entries=0): + + self.name = name + + num_entries = min_entries - len(data) + if num_entries > 0: + for i in xrange(num_entries): + data.append({}) + + super(SequenceRenderer, self).__init__( + data, + errors, + id_prefix, + ) + + def begin(self): + return self.hidden('__start__', value='%s:sequence' % self.name, id='') + + def end(self): + return self.hidden('__end__', value='%s:sequence' % self.name, id='') + + def __iter__(self): + + # what kind of data we dealing with ? + + for i, d in enumerate(self.data): + + if not isinstance(d, dict): + d = {self.name : d} + + errors = [] # to be determined + id_prefix = "%d-" % i + + yield MappingRenderer(self.name, d, errors, id_prefix=id_prefix) + + +class MappingRenderer(Renderer): + + def __init__(self, name, data, errors, id_prefix=None): + + self.name = name + + super(MappingRenderer, self).__init__( + data, + errors, + id_prefix, + ) + + def begin(self, name=None): + + name = name or self.name + + return self.hidden('__start__', value='%s:mapping' % name, id='') + + def end(self, name=None): + + name = name or self.name + + return self.hidden('__end__', value='%s:mapping' % name, id='') + + Index: b/pyramid_simpleform/tests.py =================================================================== --- a/pyramid_simpleform/tests.py +++ b/pyramid_simpleform/tests.py @@ -7,7 +7,7 @@ from pyramid import testing from pyramid.config import Configurator -class SimpleSchema(Schema): +class SimpleFESchema(Schema): name = validators.NotEmpty() @@ -17,6 +17,7 @@ class SimpleObj(object): def __init__(self, name=None): self.name = name + class TestState(unittest.TestCase): def test_state(self): @@ -43,6 +44,12 @@ class TestState(unittest.TestCase): obj = State(foo="bar") self.assert_(obj['foo'] == 'bar') + def test_getitem_notfound(self): + + from pyramid_simpleform import State + obj = State() + self.assertRaises(KeyError, obj.__getitem__, 'foo') + def test_setitem(self): from pyramid_simpleform import State @@ -59,16 +66,15 @@ class TestState(unittest.TestCase): self.assert_(obj.get('bar', 'foo') == 'foo') -class TestForm(unittest.TestCase): +class TestFormencodeForm(unittest.TestCase): - def test_is_error(self): from pyramid_simpleform import Form request = testing.DummyRequest() request.method = "POST" - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) self.assert_(not(form.validate())) self.assert_(form.is_validated) @@ -81,7 +87,7 @@ class TestForm(unittest.TestCase): request = testing.DummyRequest() request.method = "POST" - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) form.errors = u"Name is missing" self.assert_(form.all_errors() == [u"Name is missing"]) @@ -92,7 +98,7 @@ class TestForm(unittest.TestCase): request = testing.DummyRequest() request.method = "POST" - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) form.errors = [u"Name is missing"] self.assert_(form.all_errors() == [u"Name is missing"]) @@ -103,12 +109,12 @@ class TestForm(unittest.TestCase): request = testing.DummyRequest() request.method = "POST" - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) form.errors = {"name" : [u"Name is missing"], "value" : u"Value is missing"} - self.assert_(form.all_errors() == [ + self.assert_(sorted(form.all_errors()) == sorted([ u"Name is missing", - u"Value is missing"]) + u"Value is missing"])) def test_errors_for(self): from pyramid_simpleform import Form @@ -116,7 +122,7 @@ class TestForm(unittest.TestCase): request = testing.DummyRequest() request.method = "POST" - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) self.assert_(not(form.validate())) self.assert_(form.is_validated) @@ -180,10 +186,21 @@ class TestForm(unittest.TestCase): request = testing.DummyRequest() request.method = "POST" - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) self.assert_(not(form.validate())) self.assert_(form.is_validated) + + def test_is_validated_with_specified_params(self): + from pyramid_simpleform import Form + + request = testing.DummyRequest() + request.method = "POST" + + form = Form(request, SimpleFESchema) + form.validate(params={'name' : 'foo'}) + obj = form.bind(SimpleObj()) + self.assert_(obj.name == 'foo') def test_bind(self): from pyramid_simpleform import Form @@ -192,7 +209,7 @@ class TestForm(unittest.TestCase): request.method = "POST" request.POST['name'] = 'test' - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) form.validate() obj = form.bind(SimpleObj()) self.assert_(obj.name == 'test') @@ -208,10 +225,10 @@ class TestForm(unittest.TestCase): class SimpleObjWithPrivate(SimpleObj): _ignoreme = None - class SimpleSchemaWithPrivate(SimpleSchema): + class SimpleFESchemaWithPrivate(SimpleFESchema): _ignoreme = validators.String() - form = Form(request, SimpleSchemaWithPrivate) + form = Form(request, SimpleFESchemaWithPrivate) form.validate() obj = form.bind(SimpleObjWithPrivate()) self.assert_(obj.name == 'test') @@ -224,7 +241,7 @@ class TestForm(unittest.TestCase): request.method = "POST" request.POST['name'] = 'test' - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) self.assertRaises(RuntimeError, form.bind, SimpleObj()) def test_bind_with_errors(self): @@ -234,7 +251,7 @@ class TestForm(unittest.TestCase): request.method = "POST" request.POST['name'] = '' - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) self.assert_(not form.validate()) self.assertRaises(RuntimeError, form.bind, SimpleObj()) @@ -245,7 +262,7 @@ class TestForm(unittest.TestCase): request.method = "POST" request.POST['name'] = 'test' - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) form.validate() obj = form.bind(SimpleObj(), exclude=["name"]) self.assert_(obj.name == None) @@ -257,7 +274,7 @@ class TestForm(unittest.TestCase): request.method = "POST" request.POST['name'] = 'test' - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) form.validate() obj = form.bind(SimpleObj(), include=['foo']) self.assert_(obj.name == None) @@ -266,7 +283,7 @@ class TestForm(unittest.TestCase): from pyramid_simpleform import Form request = testing.DummyRequest() - form = Form(request, SimpleSchema, obj=SimpleObj(name='test')) + form = Form(request, SimpleFESchema, obj=SimpleObj(name='test')) self.assert_(form.data['name'] == 'test') @@ -274,7 +291,7 @@ class TestForm(unittest.TestCase): from pyramid_simpleform import Form request = testing.DummyRequest() - form = Form(request, SimpleSchema, defaults={'name' : 'test'}) + form = Form(request, SimpleFESchema, defaults={'name' : 'test'}) self.assert_(form.data['name'] == 'test') @@ -282,7 +299,7 @@ class TestForm(unittest.TestCase): from pyramid_simpleform import Form request = testing.DummyRequest() - form = Form(request, SimpleSchema, + form = Form(request, SimpleFESchema, obj=SimpleObj(name='test1'), defaults={'name' : 'test2'}) @@ -295,7 +312,7 @@ class TestForm(unittest.TestCase): request.POST['name'] = 'test' request.method = "POST" - form = Form(request, SimpleSchema, + form = Form(request, SimpleFESchema, variable_decode=True) self.assert_(form.validate()) @@ -308,10 +325,34 @@ class TestForm(unittest.TestCase): request.method = "GET" request.GET['name'] = 'test' - form = Form(request, SimpleSchema, method="GET") + form = Form(request, SimpleFESchema, method="GET") self.assert_(form.validate()) self.assert_(form.is_validated) + + def test_validate_from_GET_if_on_POST(self): + from pyramid_simpleform import Form + + request = testing.DummyRequest() + request.method = "GET" + request.GET['name'] = 'test' + + form = Form(request, SimpleFESchema) + + self.assert_(not form.validate()) + self.assert_(not form.is_validated) + + + def test_force_validate(self): + from pyramid_simpleform import Form + + request = testing.DummyRequest() + request.GET['name'] = 'test' + + form = Form(request, SimpleFESchema) + + self.assert_(form.validate(force_validate=True)) + self.assert_(form.is_validated) def test_render_without_htmlfill(self): @@ -327,14 +368,11 @@ class TestForm(unittest.TestCase): config = Configurator(settings=settings) - config.add_renderer('.html', - 'pyramid.mako_templating.renderer_factory') - request.registry = config.registry - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) - result = form.render("test_form.html", htmlfill=False) + result = form.render("test_form.mako", htmlfill=False) self.assert_('<input type="text" name="name" size="20">' in result) @@ -353,15 +391,12 @@ class TestForm(unittest.TestCase): config = Configurator(settings=settings) - config.add_renderer('.html', - 'pyramid.mako_templating.renderer_factory') - request.registry = config.registry - form = Form(request, SimpleSchema, defaults={'name' : 'foo'}) + form = Form(request, SimpleFESchema, defaults={'name': 'foo'}) - result = form.render("test_form.html", htmlfill=True) - self.assert_('<input type="text" name="name" size="20" value="foo">' + result = form.render("test_form.mako", htmlfill=True) + self.assert_('<input type="text" name="name" size="20" value="foo">' in result) @@ -369,8 +404,8 @@ class TestForm(unittest.TestCase): from pyramid_simpleform import Form request = testing.DummyRequest() - form = Form(request, SimpleSchema, - defaults={"name" : "testing"}) + form = Form(request, SimpleFESchema, + defaults={"name": "testing"}) html = """ <form method="POST" action="."> @@ -382,14 +417,14 @@ class TestForm(unittest.TestCase): self.assert_('value="testing"' in html) -class TestFormRenderer(unittest.TestCase): - +class TestFormencodeFormRenderer(unittest.TestCase): + def test_begin_form(self): from pyramid_simpleform import Form from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) renderer = FormRenderer(form) self.assert_(renderer.begin(url="/"), @@ -400,33 +435,33 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) renderer = FormRenderer(form) - self.assert_(renderer.end() == "</form>") + self.assertEqual(renderer.end(), "</form>") def test_csrf(self): from pyramid_simpleform import Form from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) renderer = FormRenderer(form) - self.assert_(renderer.csrf() == \ - '<input id="_csrf" name="_csrf" type="hidden" value="csrft" />') + self.assertEqual(renderer.csrf(), + '<input id="_csrf" name="_csrf" type="hidden" value="0123456789012345678901234567890123456789" />') def test_csrf_token(self): from pyramid_simpleform import Form from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) renderer = FormRenderer(form) self.assert_(renderer.csrf_token() == \ '<div style="display:none;"><input id="_csrf" name="_csrf" ' - 'type="hidden" value="csrft" /></div>') + 'type="hidden" value="0123456789012345678901234567890123456789" /></div>') def test_hidden_tag_with_csrf_and_other_names(self): @@ -434,13 +469,13 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema, defaults={'name':'foo'}) + form = Form(request, SimpleFESchema, defaults={'name':'foo'}) renderer = FormRenderer(form) self.assert_(renderer.hidden_tag('name') == \ '<div style="display:none;"><input id="name" name="name" ' 'type="hidden" value="foo" /><input id="_csrf" name="_csrf" ' - 'type="hidden" value="csrft" /></div>') + 'type="hidden" value="0123456789012345678901234567890123456789" /></div>') def test_hidden_tag_with_just_csrf(self): @@ -448,23 +483,20 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) renderer = FormRenderer(form) self.assert_(renderer.hidden_tag() == \ '<div style="display:none;"><input id="_csrf" name="_csrf" ' - 'type="hidden" value="csrft" /></div>') + 'type="hidden" value="0123456789012345678901234567890123456789" /></div>') - - - def test_text(self): from pyramid_simpleform import Form from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema, defaults={"name" : "Fred"}) + form = Form(request, SimpleFESchema, defaults={"name" : "Fred"}) renderer = FormRenderer(form) self.assert_(renderer.text("name") == \ @@ -475,7 +507,7 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema, defaults={"name" : "Fred"}) + form = Form(request, SimpleFESchema, defaults={"name" : "Fred"}) renderer = FormRenderer(form) self.assert_(renderer.textarea("name") == \ @@ -486,7 +518,7 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema, defaults={"name" : "Fred"}) + form = Form(request, SimpleFESchema, defaults={"name" : "Fred"}) renderer = FormRenderer(form) self.assert_(renderer.hidden("name") == \ @@ -497,7 +529,7 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema, defaults={"name" : "Fred"}) + form = Form(request, SimpleFESchema, defaults={"name" : "Fred"}) renderer = FormRenderer(form) options = [ @@ -521,7 +553,7 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) renderer = FormRenderer(form) self.assert_(renderer.file('file') == \ @@ -533,7 +565,7 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) renderer = FormRenderer(form) self.assert_(renderer.password('password') == \ @@ -546,7 +578,7 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema, defaults={"name" : 'Fred'}) + form = Form(request, SimpleFESchema, defaults={"name" : 'Fred'}) renderer = FormRenderer(form) self.assert_(renderer.radio("name", value="Fred") == \ @@ -563,7 +595,7 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) renderer = FormRenderer(form) self.assert_(renderer.submit("submit", "Submit") == \ @@ -574,7 +606,7 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema, defaults={"name" : True}) + form = Form(request, SimpleFESchema, defaults={"name" : True}) renderer = FormRenderer(form) self.assert_(renderer.checkbox("name") == \ @@ -588,7 +620,7 @@ class TestFormRenderer(unittest.TestCase request = testing.DummyRequest() request.method = "POST" - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) self.assert_(not(form.validate())) @@ -603,7 +635,7 @@ class TestFormRenderer(unittest.TestCase request = testing.DummyRequest() request.method = "POST" - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) self.assert_(not(form.validate())) renderer = FormRenderer(form) @@ -618,7 +650,7 @@ class TestFormRenderer(unittest.TestCase request = testing.DummyRequest() request.method = "POST" - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) form.validate() renderer = FormRenderer(form) @@ -636,7 +668,7 @@ class TestFormRenderer(unittest.TestCase request.method = "POST" request.POST['name'] = 'test' - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) form.validate() renderer = FormRenderer(form) @@ -652,17 +684,16 @@ class TestFormRenderer(unittest.TestCase request = testing.DummyRequest() request.method = "POST" - state = State(_=lambda s:s.upper()) + state = State(_=lambda s: s.upper()) - form = Form(request, SimpleSchema, state=state) + form = Form(request, SimpleFESchema, state=state) form.validate() renderer = FormRenderer(form) - self.assert_(renderer.errorlist('name') == \ + self.assertEqual(renderer.errorlist('name'), '<ul class="error"><li>MISSING VALUE</li></ul>') - def test_errorlist_with_field(self): from pyramid_simpleform import Form @@ -671,21 +702,21 @@ class TestFormRenderer(unittest.TestCase request = testing.DummyRequest() request.method = "POST" - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) form.validate() renderer = FormRenderer(form) - self.assert_(renderer.errorlist('name') == \ + self.assertEqual(renderer.errorlist('name'), '<ul class="error"><li>Missing value</li></ul>') - + def test_label(self): from pyramid_simpleform import Form from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) renderer = FormRenderer(form) self.assert_(renderer.label("name") == \ @@ -697,7 +728,7 @@ class TestFormRenderer(unittest.TestCase from pyramid_simpleform.renderers import FormRenderer request = testing.DummyRequest() - form = Form(request, SimpleSchema) + form = Form(request, SimpleFESchema) renderer = FormRenderer(form) self.assert_(renderer.label("name", "Your name") == \ Index: b/pyramid_simpleform/templates/test_form.mako =================================================================== --- /dev/null +++ b/pyramid_simpleform/templates/test_form.mako @@ -0,0 +1,12 @@ +<!DOCTYPE HTML> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title></title> +</head> +<body> +<form method="POST" action="."> + <input type="text" name="name" size="20"> +</form> +</body> +</html>
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor