|
207
|
1 |
from iro.model.schema import Offer |
|
|
2 |
from iro.model.decorators import vRoute |
|
|
3 |
from iro.model.pool import data |
|
|
4 |
|
|
|
5 |
from iro.error import ValidateException |
|
|
6 |
|
|
|
7 |
from .dbtestcase import DBTestCase |
|
|
8 |
|
|
|
9 |
class DummyPool(): |
|
|
10 |
def run(self, f,*a,**k): |
|
|
11 |
return f(*a,**k) |
|
|
12 |
|
|
|
13 |
class ModelVaidatorTest(DBTestCase): |
|
|
14 |
"""tests for the model vaidators""" |
|
|
15 |
def setUp(self): |
|
|
16 |
DBTestCase.setUp(self) |
|
|
17 |
self.pool = data.pool |
|
|
18 |
data.pool = DummyPool() |
|
|
19 |
|
|
|
20 |
def tearDown(self): |
|
|
21 |
data.pool = self.pool |
|
|
22 |
self.pool = None |
|
|
23 |
DBTestCase.tearDown(self) |
|
|
24 |
|
|
|
25 |
def testTyp(self): |
|
|
26 |
pass |
|
|
27 |
testTyp.todo = "To implement" |
|
|
28 |
|
|
|
29 |
def testRoute(self): |
|
|
30 |
with self.session() as session: |
|
|
31 |
session.add(Offer(name="t",provider="p",typ="type")) |
|
|
32 |
vR = vRoute('type') |
|
|
33 |
self.assertEqual(vR("t",None),"t") |
|
|
34 |
self.assertEqual(vR(["t","t"],None),["t"]) |
|
|
35 |
e = self.assertRaises(ValidateException,vR, "s", None) |
|
|
36 |
self.assertEqual(str(e),'700:Route s is not valid.') |
|
|
37 |
|
|
|
38 |
def testRouteAllow(self): |
|
|
39 |
with self.session() as session: |
|
|
40 |
session.add(Offer(name="t",provider="p",typ="type")) |
|
|
41 |
vR = vRoute('type') |
|
|
42 |
e = self.assertRaises(ValidateException,vR, "t", "foo", allowString=False) |
|
|
43 |
self.assertEqual(str(e),'700:foo must be a list of routes.') |
|
|
44 |
e = self.assertRaises(ValidateException,vR, ["t"], "foo", allowList=False) |
|
|
45 |
self.assertEqual(str(e),'700:foo must be a route - No list of routes.') |
|
|
46 |
|