@@ -196,7 +196,7 @@ def testListRequests(self):
196196
197197 class MockResponseStringIo :
198198 def __init__ (self , * args , ** kwargs ):
199- self .response = None , 404
199+ self .response = None
200200
201201 def request (self , * args , ** kwargs ):
202202 self .response = {"phedex" : {
@@ -234,7 +234,7 @@ def testListCustodial(self):
234234
235235 class MockResponseStringIo :
236236 def __init__ (self , * args , ** kwargs ):
237- self .response = None , 404
237+ self .response = None
238238
239239 def request (self , * args , ** kwargs ):
240240 self .response = {"phedex" : {
@@ -268,12 +268,13 @@ def testListSubscriptions(self):
268268
269269 class MockResponseStringIo :
270270 def __init__ (self , * args , ** kwargs ):
271- self .response = None , 404
271+ self .response = None
272272
273273 def request (self , * args , ** kwargs ):
274274 self .response = {"phedex" : {
275275 "request" : [{
276- "node" : [{
276+ "node" : [
277+ {
277278 "name" : "someSite" ,
278279 "decision" : "approved" ,
279280 "time_decided" : 1300
@@ -304,7 +305,11 @@ def getresponse(self):
304305 dataset = 'somedataset'
305306 )
306307 self .assertDictEqual (
307- response , {'someSite' : ('someId' , True ), 'someSite1' : ('someId' , False )})
308+ response , {
309+ 'someSite' : (
310+ 'someId' , True ),
311+ 'someSite1' : (
312+ 'someId' , False )})
308313
309314 response = listSubscriptions (
310315 url = 'http://someurl.com/' ,
@@ -314,5 +319,38 @@ def getresponse(self):
314319 self .assertDictEqual (
315320 response , {'someSite' : ('someId' , True )})
316321
322+
323+ class TestPass_to_dynamo (unittest .TestCase ):
324+
325+ def test_pass_to_dynamo (self ):
326+
327+ class MockResponseStringIo :
328+ response = {"result" : "OK" }
329+
330+ def __init__ (self , * args , ** kwargs ):
331+ pass
332+
333+ def request (self , * args , ** kwargs ):
334+ pass
335+
336+ def getresponse (self ):
337+ return ContextualStringIO (json .dumps (self .response ))
338+
339+ from WmAgentScripts .utils import pass_to_dynamo
340+ with patch ('WmAgentScripts.utils.make_x509_conn' , MockResponseStringIo ):
341+ response = pass_to_dynamo (
342+ items = ["items1" , "item2" ],
343+ N = 10
344+ )
345+ self .assertTrue (response )
346+ MockResponseStringIo .response = {"result" : "Not OK" }
347+ with patch ('WmAgentScripts.utils.make_x509_conn' , MockResponseStringIo ):
348+ response = pass_to_dynamo (
349+ items = ["items1" , "item2" ],
350+ N = 10
351+ )
352+ self .assertFalse (response )
353+
354+
317355if __name__ == '__main__' :
318356 unittest .main ()
0 commit comments