~openerp-dev/openobject-server/trunk-missing-default-values-pza

« back to all changes in this revision

Viewing changes to openerp/tests/addons/test_convert/tests/test_convert.py

  • Committer: Antony Lesuisse
  • Date: 2014-01-31 00:52:07 UTC
  • mfrom: (4854.4.369 trunk-website-al)
  • mto: This revision was merged to the branch mainline in revision 5025.
  • Revision ID: al@openerp.com-20140131005207-mn7t6tar8cywe9hz
[MERGE] trunk-website-al

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import collections
 
2
import unittest2
 
3
from lxml import etree as ET
 
4
from lxml.builder import E
 
5
 
 
6
from openerp.tests import common
 
7
 
 
8
from openerp.tools.convert import _eval_xml
 
9
 
 
10
Field = E.field
 
11
Value = E.value
 
12
class TestEvalXML(common.TransactionCase):
 
13
    def eval_xml(self, node, obj=None, idref=None):
 
14
        return _eval_xml(obj, node, pool=None, cr=self.cr, uid=self.uid,
 
15
                         idref=idref, context=None)
 
16
 
 
17
    def test_char(self):
 
18
        self.assertEqual(
 
19
            self.eval_xml(Field("foo")),
 
20
            "foo")
 
21
        self.assertEqual(
 
22
            self.eval_xml(Field("None")),
 
23
            "None")
 
24
 
 
25
    def test_int(self):
 
26
        self.assertIsNone(
 
27
            self.eval_xml(Field("None", type='int')),
 
28
            "what the fuck?")
 
29
        self.assertEqual(
 
30
            self.eval_xml(Field(" 42  ", type="int")),
 
31
            42)
 
32
 
 
33
        with self.assertRaises(ValueError):
 
34
            self.eval_xml(Field("4.82", type="int"))
 
35
 
 
36
        with self.assertRaises(ValueError):
 
37
            self.eval_xml(Field("Whelp", type="int"))
 
38
 
 
39
    def test_float(self):
 
40
        self.assertEqual(
 
41
            self.eval_xml(Field("4.78", type="float")),
 
42
            4.78)
 
43
 
 
44
        with self.assertRaises(ValueError):
 
45
            self.eval_xml(Field("None", type="float"))
 
46
 
 
47
        with self.assertRaises(ValueError):
 
48
            self.eval_xml(Field("Foo", type="float"))
 
49
 
 
50
    def test_list(self):
 
51
        self.assertEqual(
 
52
            self.eval_xml(Field(type="list")),
 
53
            [])
 
54
 
 
55
        self.assertEqual(
 
56
            self.eval_xml(Field(
 
57
                Value("foo"),
 
58
                Value("5", type="int"),
 
59
                Value("4.76", type="float"),
 
60
                Value("None", type="int"),
 
61
                type="list"
 
62
            )),
 
63
            ["foo", 5, 4.76, None])
 
64
 
 
65
    def test_file(self):
 
66
        Obj = collections.namedtuple('Obj', 'module')
 
67
        obj = Obj('test_convert')
 
68
        self.assertEqual(
 
69
            self.eval_xml(Field('test_file.txt', type='file'), obj),
 
70
            'test_convert,test_file.txt')
 
71
 
 
72
        with self.assertRaises(IOError):
 
73
            self.eval_xml(Field('test_nofile.txt', type='file'), obj)
 
74
 
 
75
    @unittest2.skip("not tested")
 
76
    def test_xml(self):
 
77
        pass
 
78
 
 
79
    @unittest2.skip("not tested")
 
80
    def test_html(self):
 
81
        pass
 
82
 
 
83