Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(66)  |  Call(58)  |  Derive(0)  |  Import(8)

src/w/t/wtforms-HEAD/tests/ext_dateutil.py   wtforms(Download)
from wtforms.form import Form
from wtforms.ext.dateutil.fields import DateTimeField, DateField
from tests.common import DummyPostData
 
 
    def test_form_input(self):
        f = self.F(DummyPostData(a='2008/09/12 4:17 PM', b='04/05/06', c='04/05/06'))
        self.assertEqual(f.a.data, datetime(2008, 9, 12, 16, 17))
        self.assertEqual(f.a._value(), '2008/09/12 4:17 PM')
        self.assertEqual(f.b.data, date(2006, 4, 5))
        self.assertEqual(f.c.data, date(2004, 5, 6))
        self.assertTrue(f.validate())
        f = self.F(DummyPostData(a='Grok Grarg Rawr'))
    def test_blank_input(self):
        f = self.F(DummyPostData(a='', b=''))
        self.assertEqual(f.a.data, None)
        self.assertEqual(f.b.data, None)
        self.assertFalse(f.validate())

src/w/t/wtforms-HEAD/tests/fields.py   wtforms(Download)
from wtforms.compat import text_type
from wtforms.utils import unset_value
from tests.common import DummyPostData
 
PYTHON_VERSION = sys.version_info
    def test_failure(self):
        form = self.F(DummyPostData(a=['  foo bar  '], b=['hi']))
        self.assertEqual(form.a.data, 'foo bar')
        self.assertEqual(form.b.data, 'hi')
        self.assertEqual(len(form.b.process_errors), 1)
    def test_with_data(self):
        form = self.F(DummyPostData(a=['btest']))
        self.assertEqual(form.a.data, 'btest')
        self.assertEqual(form.a(), """<select id="a" name="a"><option value="a">hello</option><option selected value="btest">bye</option></select>""")
 
    def test_value_coercion(self):
        form = self.F(DummyPostData(b=['2']))
        self.assertEqual(form.b.data, 2)
        self.assertTrue(form.b.validate(form))
        form = self.F(DummyPostData(b=['b']))

src/w/t/wtforms-HEAD/tests/ext_sqlalchemy.py   wtforms(Download)
from wtforms.ext.sqlalchemy.orm import model_form, ModelConversionError, ModelConverter
from wtforms.validators import Optional, Required
from tests.common import DummyPostData, contains_validator
 
 
        class F(Form):
            a = QuerySelectField(get_label='name', widget=LazySelect(), get_pk=lambda x: x.id)
        form = F(DummyPostData(a=['1']))
        form.a.query = sess.query(self.Test)
        self.assertTrue(form.a.data is not None)
        self.assertFalse(form.validate())
 
        form = F(DummyPostData(a=['1'], b=['hello2']))
        self.assertEqual(form.a.data.id, 1)
        self.assertEqual(form.a(), [('1', 'apple', True), ('2', 'banana', False)])
 
        # Test bad data
        form = F(DummyPostData(b=['__None'], a=['fail']))
        assert not form.validate()
        self.assertEqual(form.a.errors, ['Not a valid choice'])
    def test_single_value_without_factory(self):
        form = self.F(DummyPostData(a=['1']))
        form.a.query = self.sess.query(self.Test)
        self.assertEqual([1], [v.id for v in form.a.data])
        self.assertEqual(form.a(), [('1', 'apple', True), ('2', 'banana', False)])

src/w/t/wtforms-HEAD/tests/ext_csrf.py   wtforms(Download)
from wtforms.ext.csrf import SecureForm
from wtforms.ext.csrf.session import SessionSecureForm
from tests.common import DummyPostData
 
import datetime
    def test_with_data(self):
        post_data = DummyPostData(csrf_token='test', a='hi')
        form = InsecureForm(post_data, csrf_context='test')
        self.assertTrue(form.validate())
        self.assertEqual(form.data, {'a': 'hi'})
    def test_with_missing_token(self):
        post_data = DummyPostData(a='hi')
        form = InsecureForm(post_data, csrf_context='test')
        self.assertFalse(form.validate())
 
    def test_timestamped(self):
        session = {}
        postdata = DummyPostData(csrf_token='fake##fake')
        form = self.SSF(postdata, csrf_context=session)
        assert 'csrf' in session
        bad_token = evil_form.csrf_token._value()
 
        postdata = DummyPostData(csrf_token=bad_token)
        form = self.SSF(postdata, csrf_context=session)
        assert not form.validate()

src/w/t/wtforms-HEAD/tests/form.py   wtforms(Download)
from wtforms.fields import TextField, IntegerField
from wtforms.validators import ValidationError
from tests.common import DummyPostData
 
 
        form['foo'] = TextField()
        self.assertEqual(len(list(form)), 2)
        form.process(DummyPostData(foo=['hello']))
        self.assertEqual(form['foo'].data, 'hello')
        form['test'] = IntegerField()
        self.assertTrue(isinstance(form['test'], IntegerField))
        self.assertEqual(len(list(form)), 2)
        self.assertRaises(AttributeError, getattr, form['test'], 'data')
        form.process(DummyPostData(test=['1']))
        self.assertEqual(form['test'].id, 'foo-test')
        form = self.get_form(prefix='foo.')
        form.process(DummyPostData({'foo.test': ['hello'], 'test': ['bye']}))
        self.assertEqual(form['test'].data, 'hello')
        self.assertEqual(self.get_form(prefix='foo[')['test'].name, 'foo[-test')

src/w/t/wtforms-HEAD/tests/ext_django/tests.py   wtforms(Download)
from ext_django import models as test_models
from unittest import TestCase
from tests.common import DummyPostData, contains_validator, assert_raises_text
from wtforms import Form, fields, validators
from wtforms.compat import text_type
        pairs = (('True', True), ('False', False), ('None', None), ('2', True), ('0', False))
        for input_val, expected in pairs:
            form = self.F(DummyPostData(nullbool=[input_val]))
            assert form.nullbool.data is expected
 
    def test_convert_input_to_current_timezone(self):
        post_data = {'a': ['2013-09-24 00:00:00']}
        form = self.F(DummyPostData(post_data))
        self.assertTrue(form.validate())
        date = form.data['a']

src/w/t/wtforms-HEAD/tests/locale_babel.py   wtforms(Download)
from wtforms.fields import DecimalField
from wtforms.utils import unset_value
from tests.common import DummyPostData
 
 
    def _parse_test(self, raw_val, expected, locales=unset_value):
        meta = None
        if locales is not unset_value:
            meta = {'locales': locales}
        form = self.F(DummyPostData(a=raw_val), meta=meta)
    def _fail_parse(self, raw_val, expected_error, locales=unset_value):
        meta = None
        if locales is not unset_value:
            meta = {'locales': locales}
        form = self.F(DummyPostData(a=raw_val), meta=meta)

src/w/t/wtforms-HEAD/tests/csrf.py   wtforms(Download)
from wtforms.csrf.core import CSRF
from wtforms.csrf.session import SessionCSRF
from tests.common import DummyPostData
 
import datetime
        assert not form.validate()
        self.assertEqual(form.csrf_token._value(), 'dummytoken')
        form = self.F(DummyPostData(csrf_token='dummytoken'))
        assert form.validate()
 
    def _test_phase2(self, form_class, session, token, must_validate=True):
        form = form_class(
            formdata=DummyPostData(csrf_token=token),
            meta={'csrf_context': session}
        )