def test_positive(self):
     'Положительный тест'
     input   = {'a' : '1', 'b' : {'c' : '2.0', 'd' : ['1', '2', '3']}}
     accepts = {'a' : int, 'b' : {'c' : (float, positive), 'd' : array(int)}}
     xml     = '<input><a type="int">1</a><b type="group"><c type="float positive">2.0</c><d type="array"><item>1</item><item>2</item><item>3</item></d></b></input>'
     
     self.assertEqual(etree.tounicode(serialize_input(input, accepts)), xml)
 def test_plain_with_lists(self):
     'Нет иерархии, правила в виде списков'
     input   = {'a' : '1', 'b' : '2.0'}
     accepts = {'a' : int, 'b' : (float, positive)}
     xml     = '<input><a type="int">1</a><b type="float positive">2.0</b></input>'
     
     self.assertEqual(etree.tounicode(serialize_input(input, accepts)), xml)
 def test_plain(self):
     'Простые правила'
     input   = {'a' : '1', 'b' : '2.0'}
     accepts = {'a' : int, 'b' : float}
     xml     = '<input><a type="int">1</a><b type="float">2.0</b></input>'
     
     self.assertEqual(etree.tounicode(serialize_input(input, accepts)), xml)
 def test_error(self):
     'Ошибка'
     input   = {'a' : '1', 'b' : '2,0'}
     accepts = {'a' : int, 'b' : float}
     errors  = {'b' : 'float'}
     xml     = '<input><a type="int">1</a><b type="float" error="float">2,0</b></input>'
     
     self.assertEqual(etree.tounicode(serialize_input(input, accepts, errors = errors)), xml)
 def test_empty_input_hierarchy(self):
     'Пустой input с иерархией'
     
     input   = {}
     accepts = {'a' : int, 'b' : {'c' : float, 'd' : float }}
     errors  = {'a' : 'absent', 'b.c' : 'absent', 'b.d' : 'absent'}
     
     xml     = '<input><a type="int" error="absent"/><b type="group"><c type="float" error="absent"/><d type="float" error="absent"/></b></input>'
     
     self.assertEqual(etree.tounicode(serialize_input(input, accepts, errors = errors)), xml)
 def test_empty_input(self):
     'Пустой input'
     
     input   = {}
     accepts = {'a' : int, 'b' : float}
     errors  = {'a' : 'absent', 'b' : 'absent'}
     
     xml     = '<input><a type="int" error="absent"/><b type="float" error="absent"/></input>'
     
     self.assertEqual(etree.tounicode(serialize_input(input, accepts, errors = errors)), xml)
 def test_positive_error(self):
     'Положительный тест с ошибками'
     
     input   = {'a' : '1,', 'b' : {'c' : '-2.0', 'd' : ['1', '2', '3']}}
     accepts = {'a' : int, 'b' : {'c' : (float, positive), 'd' : array(int)}}
     errors  = {'a' : 'int', 'b.c' : 'positive'}
     
     xml     = '<input><a type="int" error="int">1,</a><b type="group"><c type="float positive" error="positive">-2.0</c><d type="array"><item>1</item><item>2</item><item>3</item></d></b></input>'
     
     self.assertEqual(etree.tounicode(serialize_input(input, accepts, errors = errors)), xml)
 def test_empty(self):
     'Пустое дерево'
     self.assertEqual(etree.tounicode(serialize_input({}, {})), '<input/>')