Esempio n. 1
0
    def test_disabled_form(self):
        options = [('bar1', "Bar 1"), ('bar2', "Bar 2"), ('bar3', "Bar 3")]
        context = dict(disabled_form=True)
        expected = '''
<div>
<label for="foo">Foo:</label><select disabled id="foo" name="foo">
<option value=""></option>
<option value="bar1">Bar 1</option>
<option value="bar2">Bar 2</option>
<option value="bar3">Bar 3</option></select>
</div>
'''.strip()
        result = form_fields.select(context, 'foo', "Foo:", options)
        result = lxml.html.tostring(result, pretty_print=True).strip()
        self.assertEqual(expected, result)

        options = [('bar1', "Bar 1"), ('bar2', "Bar 2"), ('bar3', "Bar 3")]
        context = dict(disabled_form=False)
        expected = '''
<div>
<label for="foo">Foo:</label><select id="foo" name="foo">
<option value=""></option>
<option value="bar1">Bar 1</option>
<option value="bar2">Bar 2</option>
<option value="bar3">Bar 3</option></select>
</div>
'''.strip()
        result = form_fields.select(context, 'foo', "Foo:", options)
        result = lxml.html.tostring(result, pretty_print=True).strip()
        self.assertEqual(expected, result)
Esempio n. 2
0
    def test_non_ascii(self):
        options = [(1, "One"), (2, "2"), ('3', u"Bar £")]
        context = dict(data={'foo': "2"})
        expected = '''
<div>
<label for="foo">Foo:</label><select id="foo" name="foo">
<option value="1">One</option>
<option selected value="2">2</option>
<option value="3">Bar &#163;</option></select>
</div>
'''.strip()
        result = form_fields.select(context, 'foo', "Foo:", options, blank_option=False)
        result = lxml.html.tostring(result, pretty_print=True).strip()
        self.assertEqual(expected, result)
Esempio n. 3
0
    def test_plain(self):
        options = [('bar1', "Bar 1"), ('bar2', "Bar 2"), ('bar3', "Bar 3")]
        expected = '''
<div>
<label for="foo">Foo:</label><select id="foo" name="foo">
<option value=""></option>
<option value="bar1">Bar 1</option>
<option value="bar2">Bar 2</option>
<option value="bar3">Bar 3</option></select>
</div>
        '''.strip()
        result = form_fields.select({}, 'foo', "Foo:", options)
        result = lxml.html.tostring(result, pretty_print=True).strip()
        self.assertEqual(expected, result)
Esempio n. 4
0
    def test_without_blank_option(self):
        options = [('bar1', "Bar 1"), ('bar2', "Bar 2"), ('bar3', "Bar 3")]
        context = dict()
        expected = '''
<div>
<label for="foo">Foo:</label><select id="foo" name="foo">
<option value="bar1">Bar 1</option>
<option value="bar2">Bar 2</option>
<option value="bar3">Bar 3</option></select>
</div>
'''.strip()
        result = form_fields.select(context, 'foo', "Foo:", options, blank_option=False)
        result = lxml.html.tostring(result, pretty_print=True).strip()
        assert expected == result
Esempio n. 5
0
    def test_with_values(self):
        options = ["one", "two", "three"]
        context = dict()
        expected = '''
<div>
<label for="foo">Foo:</label><select id="foo" name="foo">
<option value=""></option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option></select>
</div>
        '''.strip()
        result = form_fields.select(context, 'foo', "Foo:", options)
        result = lxml.html.tostring(result, pretty_print=True).strip()
        self.assertEqual(expected, result)
Esempio n. 6
0
    def test_errors(self):
        options = [('bar1', "Bar 1"), ('bar2', "Bar 2"), ('bar3', "Bar 3")]
        context = dict(errors=dict(foo='Please choose a foo'))
        expected = '''
<div>
<label for="foo">Foo:</label><select id="foo" name="foo">
<option value=""></option>
<option value="bar1">Bar 1</option>
<option value="bar2">Bar 2</option>
<option value="bar3">Bar 3</option></select><span class="error">Please choose a foo</span>
</div>
        '''.strip()
        result = form_fields.select(context, 'foo', "Foo:", options)
        result = lxml.html.tostring(result, pretty_print=True).strip()
        self.assertEqual(expected, result)
Esempio n. 7
0
    def test_compulsory(self):
        options = [('bar1', "Bar 1"), ('bar2', "Bar 2"), ('bar3', "Bar 3")]
        expected = '''
<div>
<label for="foo">Foo:*</label><select id="foo" name="foo">
<option value=""></option>
<option value="bar1">Bar 1</option>
<option value="bar2">Bar 2</option>
<option value="bar3">Bar 3</option></select>
</div>
        '''.strip()
        result = wrappers.compulsory(
            form_fields.select({}, 'foo', "Foo:", options))
        result = lxml.html.tostring(result, pretty_print=True).strip()
        assert expected == result