def test_ipp_display_widget(): from pyipptool.widgets import IPPDisplayWidget widget = IPPDisplayWidget() rendrer = DummyRenderer() field = DummyField(None, renderer=rendrer) response = widget.serialize(field, None) assert response == 'DISPLAY name'
def test_deserialize_null(self): from colander import null widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) self.assertTrue(widget.deserialize(field, null) is null)
def test_deserialize_list(self): widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) self.assertEqual(widget.deserialize(field, ['abc', 'def']), ('abc', 'def'))
def test_ipp_attribute_widget_null(): from pyipptool.widgets import IPPAttributeWidget widget = IPPAttributeWidget() rendrer = DummyRenderer() field = DummyField(None, renderer=rendrer) response = widget.serialize(field, colander.null) assert response == ''
def test_deserialize_empty_date(self): from colander import Invalid widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) pstruct = {'date': '', 'time': '09:28:37'} self.assertRaises(Invalid, widget.deserialize, field, pstruct)
def test_deserialize_w_time_no_seconds(self): widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) pstruct = {'date': '2013-05-03', 'time': '09:28'} cstruct = widget.deserialize(field, pstruct) self.assertEqual(cstruct, '2013-05-03 09:28:00')
def test_deserialize_empty_date_and_time(self): from colander import null widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) pstruct = {'date': '', 'time': ''} self.assertTrue(widget.deserialize(field, pstruct) is null)
def test_serialize_None(self): widget = self._makeOne() renderer = DummyRenderer() field = DummyField(None, renderer=renderer) widget.serialize(field, None) self.assertEqual(renderer.template, widget.template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['cstruct'], '')
def test_ipp_file_widget_with_None(): from pyipptool.widgets import IPPFileWidget widget = IPPFileWidget() rendrer = DummyRenderer() field = DummyField(None, renderer=rendrer) with pytest.raises(ValueError): widget.serialize(field, None)
def test_serialize_null(self): from colander import null widget = self._makeOne() renderer = DummyRenderer() field = DummyField(None, renderer=renderer) widget.serialize(field, null) self.assertEqual(renderer.template, widget.template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['cstruct'], '')
def test_ipp_attribute_widget_with_value(): from pyipptool.widgets import IPPAttributeWidget widget = IPPAttributeWidget() rendrer = DummyRenderer() schema = DummySchema() schema.typ = DummyType() field = DummyField(schema, renderer=rendrer) response = widget.serialize(field, 'hello') assert response == 'ATTR dummyType name hello'
def test_ipp_file_widget(): from pyipptool.widgets import IPPFileWidget widget = IPPFileWidget() rendrer = DummyRenderer() field = DummyField(None, renderer=rendrer) response = widget.serialize(field, '/path/to/file.txt') assert response == 'FILE /path/to/file.txt'
def test_serialize_not_null_readonly(self): widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) widget.serialize(field, '2013-05-03 09:28:37', readonly=True) self.assertEqual(renderer.template, widget.readonly_template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['date'], '2013-05-03') self.assertEqual(renderer.kw['time'], '09:28:37')
def test_serialize_wo_tz(self): widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) widget.serialize(field, '2013-05-03T09:28:37') self.assertEqual(renderer.template, widget.template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['date'], '2013-05-03') self.assertEqual(renderer.kw['time'], '09:28:37')
def test_ipp_attribute_widget_with_None(): from pyipptool.widgets import IPPAttributeWidget widget = IPPAttributeWidget() rendrer = DummyRenderer() schema = DummySchema() schema.typ = DummyType() field = DummyField(schema, renderer=rendrer) with pytest.raises(ValueError) as exc_info: widget.serialize(field, None) assert str(exc_info.value) == "None value provided for 'name'"
def test_serialize_not_null_readonly(self): widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) cstruct = 'abc' widget.serialize(field, cstruct, readonly=True) self.assertEqual(renderer.template, widget.readonly_template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['cstruct'], cstruct)
def test_serialize_None(self): widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) widget.serialize(field, None) self.assertEqual(renderer.template, widget.template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['date'], '') self.assertEqual(renderer.kw['time'], '')
def test_serialize_null(self): from colander import null widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) widget.serialize(field, null) self.assertEqual(renderer.template, widget.template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['date'], '') self.assertEqual(renderer.kw['time'], '')
def test_ipp_name_widget(): from pyipptool.widgets import IPPNameWidget widget = IPPNameWidget() rendrer = DummyRenderer() schema = DummySchema(name='FOO') field = DummyField(schema, renderer=rendrer) field.parent = None sub_field = DummyField(None, renderer=rendrer) sub_field.parent = field response = widget.serialize(sub_field, 'world') assert response == 'NAME "FOO"'
def test_serialize_not_null(self): widget = self._makeOne() renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) widget.values = [{ 'label': 'alphabet', 'values': [('abc', 'ABC'), ('def', 'DEF')], }] widget.serialize(field, 'abc') self.assertEqual(renderer.template, widget.template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['cstruct'], 'abc')
def test_serialize_iterable(self): widget = self._makeOne() values = [1, 2, 3, 4] widget.values = values renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) cstruct = 'abc' widget.serialize(field, cstruct) self.assertEqual(renderer.template, widget.template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['cstruct'], cstruct) renderer_options = json.loads('{"source": ' + renderer.kw['values'] + renderer.kw['options'] + '}') self.assertEqual(renderer_options['source'], values)
def test_serialize_remote(self): widget = self._makeOne(min_length=2, items=5) values = '/items' widget.source = values renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) cstruct = 'abc' widget.serialize(field, cstruct) self.assertEqual(renderer.template, widget.template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['cstruct'], cstruct) self.assertEqual(renderer.kw['values'], ('function (query, process){' '$.getJSON("/items", {"term": query}, process);}')) self.assertEqual(renderer.kw['options'], ', "minLength": 2, "items": 5')
def test_serialize_url(self): import json from deform.tests.test_widget import ( DummyRenderer, DummyField, DummySchema, ) request = testing.DummyRequest() request.mgmt_path = lambda req, name: 'myurl' widget = self._makeOne(request) renderer = DummyRenderer() schema = DummySchema() field = DummyField(schema, renderer=renderer) cstruct = 'abc' widget.serialize(field, cstruct) self.assertEqual(renderer.template, widget.template) self.assertEqual(renderer.kw['field'], field) self.assertEqual(renderer.kw['cstruct'], cstruct) self.assertEqual(renderer.kw['options'], '{"delay": 400, "minLength": 2}') self.assertEqual(renderer.kw['values'], json.dumps('myurl'))