]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/wradmin/tests/test_models.py
35fbbce02bbb30ae533487089db6bebce9d688a8
[philipp/winterrodeln/wradmin.git] / wradmin / wradmin / tests / test_models.py
1 # -*- coding: iso-8859-15 -*-
2 import wradmin.model.validators
3 import formencode
4
5
6 def test_NoneValidator():
7     v =  wradmin.model.validators.NoneValidator(wradmin.model.validators.Unicode())
8     assert v.to_python(u'') == None
9     assert v.from_python(None) == u''
10
11
12 def test_UnsignedNone():
13     v = wradmin.model.validators.UnsignedNone()
14     assert v.to_python(u'42') == 42
15     assert v.to_python(u'') == None
16     assert v.from_python(42) == u'42'
17     assert v.from_python(None) == u''
18
19
20 def test_GeoNone():
21     coord = u'47.076207 N 11.453553 E'
22     v = wradmin.model.validators.GeoNone()
23     (lat, lon) = v.to_python(coord)
24     assert lat == 47.076207
25     assert lon == 11.453553
26     assert v.to_python(u'') == (None, None)
27
28     assert v.from_python((lat, lon)) == coord
29     assert v.from_python((None, None)) == u''
30
31
32 def test_GermanTristateTuple():
33     v = wradmin.model.validators.GermanTristateTuple()
34     assert v.to_python(u'') == (None, None)
35     assert v.to_python(u'Ja') == (True, False)
36     assert v.to_python(u'Nein') == (False, True)
37     assert v.to_python(u'Teilweise') == (True, True)
38     assert v.from_python((None, None)) == u''
39     assert v.from_python((False, True)) == u'Nein'
40     assert v.from_python((True, False)) == u'Ja'
41     assert v.from_python((True, True)) == u'Teilweise'
42
43
44 def tes_GermanTristateFloat():
45     v = wradmin.model.validators.GermanTristateFloat()
46     assert v.to_python(u'') == None
47     assert v.to_python(u'Ja') == 1.0
48     assert v.to_python(u'Nein') == 0.0
49     assert v.to_python(u'Teilweise') == 0.5
50     assert v.from_python(None) == u''
51     assert v.from_python(0.0) == u'Nein'
52     assert v.from_python(1.0) == u'Ja'
53     assert v.from_python(0.5) == u'Teilweise'
54
55
56 def test_ValueCommentList():
57     v = wradmin.model.validators.ValueCommentList()
58     assert v.to_python(u'abc') == [(u'abc', None)]
59     assert v.to_python(u'abc def') == [(u'abc def', None)]
60     assert v.to_python(u'value (comment)') == [(u'value', u'comment')]
61     assert v.to_python(u'value (comment)') == [(u'value', u'comment')]
62     assert v.to_python(u'value1 (comment); value2') == [(u'value1', u'comment'), (u'value2', None)]
63     assert v.to_python(u'value1 (comment1); value2; value3 (comment3)') == [(u'value1', u'comment1'), (u'value2', None), ('value3', 'comment3')]
64     assert v.to_python(u'value1 (comment1); value2 (test (not easy))') == [(u'value1', u'comment1'), (u'value2', u'test (not easy)')]
65
66
67 def test_UrlNeinNone():
68     v = wradmin.model.validators.UrlNeinNone()
69     assert v.to_python(u'') == None
70     assert v.to_python(u'Nein') == u'Nein'
71     assert v.to_python(u'http://www.höttingeralm.at') == u'http://www.höttingeralm.at'
72     assert v.from_python(None) == u''
73     assert v.from_python(u'Nein') == u'Nein'
74     assert v.from_python(u'http://www.höttingeralm.at') == u'http://www.höttingeralm.at'
75
76
77 def test_ValueCommentListNeinLoopNone():
78     v = wradmin.model.validators.ValueCommentListNeinLoopNone()
79     assert v.to_python(u'') == None
80     assert v.to_python(u'Nein') == u'Nein'
81     assert v.to_python(u'T-Mobile (gut); A1') == u'T-Mobile (gut); A1'
82     assert v.from_python(None) == u''
83     assert v.from_python(u'Nein') == u'Nein'
84     assert v.from_python(u'T-Mobile (gut); A1') == u'T-Mobile (gut); A1'
85     
86
87 def test_PhoneCommentListNeinLoopNone():
88     v = wradmin.model.validators.PhoneCommentListNeinLoopNone(comments_are_optional=True)
89     assert v.to_python(u'') == None
90     assert v.to_python(u'Nein') == u'Nein'
91     assert v.to_python(u'+43-699-1234567 (nicht nach 20:00 Uhr); +43-512-123456') == u'+43-699-1234567 (nicht nach 20:00 Uhr); +43-512-123456'
92     assert v.from_python(None) == u''
93     assert v.from_python(u'Nein') == u'Nein'
94     assert v.from_python(u'+43-699-1234567 (nicht nach 20:00 Uhr); +43-512-123456') == u'+43-699-1234567 (nicht nach 20:00 Uhr); +43-512-123456'
95
96
97 def test_EmailCommentListNeinLoopNone():
98     v = wradmin.model.validators.EmailCommentListNeinLoopNone()
99     assert v.to_python(u'') == None
100     assert v.to_python(u'Nein') == u'Nein'
101     assert v.to_python(u'first@example.com') == u'first@example.com'
102     assert v.to_python(u'first@example.com (Nur Winter); second@example.com') == u'first@example.com (Nur Winter); second@example.com'
103     assert v.from_python(None) == u''
104     assert v.from_python(u'Nein') == u'Nein'
105     assert v.from_python(u'first@example.com') == u'first@example.com'
106     assert v.from_python(u'first@example.com (Nur Winter); second@example.com') == u'first@example.com (Nur Winter); second@example.com'
107
108
109 def test_GermanLift():
110     v = wradmin.model.validators.GermanLift()
111     assert v.to_python(u'') == (None, None)
112     assert v.to_python(u'Nein') == (False, None)
113     assert v.to_python(u'Sessellift (4 Euro)') == (True, u'Sessellift (4 Euro)')
114     assert v.from_python((None, None)) == u''
115     assert v.from_python((False, None)) == u'Nein'
116     assert v.from_python((True, u'Sessellift (4 Euro)')) == u'Sessellift (4 Euro)'
117
118
119 def test_WikiPageListLoopNone():
120     v = wradmin.model.validators.WikiPageListLoopNone()
121     assert v.to_python(u'') == None
122     assert v.to_python(u'[[Birgitzer Alm]]; [[Kemater Alm]]') == u'[[Birgitzer Alm]]; [[Kemater Alm]]'
123     assert v.from_python(None) == u''
124     assert v.from_python(u'[[Birgitzer Alm]]; [[Kemater Alm]]') == u'[[Birgitzer Alm]]; [[Kemater Alm]]'
125
126
127 def test_BoolUnicodeTupleValidator():
128     v = wradmin.model.validators.BoolUnicodeTupleValidator()
129     assert v.to_python(u'') == (None, None)
130     assert v.to_python(u'Nein') == (False, None)
131     assert v.to_python(u'any text') == (True, u'any text')
132     assert v.from_python((None, None)) == u''
133     assert v.from_python((False, None)) == u'Nein'
134     assert v.from_python((True, u'any text')) == u'any text'
135
136
137 def test_SledRental():
138     v = wradmin.model.validators.SledRental()
139     assert v.to_python(u'') == (None, None)
140     assert v.to_python(u'Nein') == (False, None)
141     assert v.to_python(u'Ja') == (True, u'Ja')
142     assert v.to_python(u'Talstation (nur mit Ticket); Schneealm') == (True, u'Talstation (nur mit Ticket); Schneealm')
143     assert v.from_python((None, None)) == u''
144     assert v.from_python((False, None)) == u'Nein'
145     assert v.from_python((True, u'Talstation (nur mit Ticket); Schneealm')) == u'Talstation (nur mit Ticket); Schneealm'
146     assert v.from_python((True, u'Ja')) == u'Ja'