11from tests import PyResTests , Basic , TestProcess , ErrorObject
22from pyres import failure
3+ from pyres .failure .base import BaseBackend
4+ from pyres .failure .multiple import MultipleBackend
5+ from pyres .failure .redis import RedisBackend
36from pyres .job import Job
7+
48class FailureTests (PyResTests ):
59 def test_count (self ):
610 self .resq .enqueue (Basic ,"test1" )
711 job = Job .reserve ('basic' ,self .resq )
812 job .fail ("problem" )
913 assert failure .count (self .resq ) == 1
1014 assert self .redis .llen ('resque:failed' ) == 1
11-
15+
1216 def test_create (self ):
1317 self .resq .enqueue (Basic ,"test1" )
1418 job = Job .reserve ('basic' ,self .resq )
1519 e = Exception ('test' )
1620 fail = failure .create (e , 'basic' , job ._payload )
1721 assert isinstance (fail ._payload , dict )
18- fail .save ()
22+ fail .save (self . resq )
1923 assert failure .count (self .resq ) == 1
2024 assert self .redis .llen ('resque:failed' ) == 1
21-
25+
2226 def test_all (self ):
2327 self .resq .enqueue (Basic ,"test1" )
2428 job = Job .reserve ('basic' ,self .resq )
2529 e = Exception ('problem' )
2630 job .fail (e )
2731 assert len (failure .all (self .resq , 0 , 20 )) == 1
28-
32+
2933 def test_clear (self ):
3034 self .resq .enqueue (Basic ,"test1" )
3135 job = Job .reserve ('basic' ,self .resq )
@@ -34,7 +38,7 @@ def test_clear(self):
3438 assert self .redis .llen ('resque:failed' ) == 1
3539 failure .clear (self .resq )
3640 assert self .redis .llen ('resque:failed' ) == 0
37-
41+
3842 def test_requeue (self ):
3943 self .resq .enqueue (Basic ,"test1" )
4044 job = Job .reserve ('basic' ,self .resq )
@@ -45,4 +49,21 @@ def test_requeue(self):
4549 assert self .resq .size ('basic' ) == 1
4650 job = Job .reserve ('basic' ,self .resq )
4751 assert job ._queue == 'basic'
48- assert job ._payload == {'class' :'tests.Basic' ,'args' :['test1' ]}
52+ assert job ._payload == {'class' :'tests.Basic' ,'args' :['test1' ]}
53+
54+ # Test the MultipleBackend, basically just repeat the above tests, ensuring that
55+ # we've delegated to the methods appropriately
56+
57+ class TestBackend (BaseBackend ):
58+ def save (self , resq ):
59+ resq .redis .set ('testbackend:called' , 1 )
60+
61+ failure .backend = MultipleBackend
62+ failure .backend .classes = [RedisBackend , TestBackend ]
63+
64+ class MultipleFailureTests (FailureTests ):
65+ def test_create (self ):
66+ # Run the parent test
67+ FailureTests .test_create (self )
68+ # But also ensure the other backends were called
69+ assert int (self .redis .get ('testbackend:called' )) == 1
0 commit comments