@@ -408,6 +408,7 @@ def test_is_json(self):
408
408
class TestReadFile (unittest .TestCase ):
409
409
410
410
def test_read_file (self ):
411
+
411
412
from WmAgentScripts .utils import read_file
412
413
test_json = {
413
414
"first" : {"a" : "A" },
@@ -452,7 +453,9 @@ def getresponse(self):
452
453
class TestCheckTransferApproval (unittest .TestCase ):
453
454
454
455
def test_checkTransferApproval (self ):
456
+
455
457
class MockResponseStringIo :
458
+
456
459
def __init__ (self , * args , ** kwargs ):
457
460
self .response = None
458
461
@@ -490,7 +493,9 @@ def getresponse(self):
490
493
class TestGetNodesId (unittest .TestCase ):
491
494
492
495
def test_getNodesId (self ):
496
+
493
497
class MockResponseStringIo :
498
+
494
499
def __init__ (self , * args , ** kwargs ):
495
500
self .response = None
496
501
@@ -524,7 +529,9 @@ def getresponse(self):
524
529
525
530
526
531
class TestGetDatasetFileLocations (unittest .TestCase ):
532
+
527
533
def test_getDatasetFileLocations (self ):
534
+
528
535
class MockResponseStringIo :
529
536
def __init__ (self , * args , ** kwargs ):
530
537
self .response = None
@@ -553,12 +560,15 @@ def request(self, *args, **kwargs):
553
560
554
561
def getresponse (self ):
555
562
return ContextualStringIO (json .dumps (self .response ))
563
+
556
564
from WmAgentScripts .utils import getDatasetFileLocations
565
+
557
566
with patch ('WmAgentScripts.utils.make_x509_conn' , MockResponseStringIo ):
558
567
response = getDatasetFileLocations (
559
568
url = 'http://someurl.com/' ,
560
569
dataset = 'somedataset'
561
570
)
571
+
562
572
self .assertDictEqual (
563
573
response , {
564
574
'someSite' : set (['someNode' ]),
@@ -637,5 +647,50 @@ def test_getConfigurationLine(self):
637
647
self .assertEqual (response , "Test2 line 2" )
638
648
639
649
650
+ class TestGetWorkflowByCampaign (unittest .TestCase ):
651
+
652
+ def test_getWorkflowByCampaign (self ):
653
+
654
+ class MockResponseStringIo :
655
+
656
+ def __init__ (self , * args , ** kwargs ):
657
+ self .response = None
658
+
659
+ def request (self , * args , ** kwargs ):
660
+ self .response = {"result" :
661
+ [{"data" : [
662
+ {
663
+ "name" : "someSite" ,
664
+ },
665
+ {
666
+ "name" : "someSite1" ,
667
+ },
668
+ ],
669
+ }]
670
+ }
671
+
672
+ def getresponse (self ):
673
+ return ContextualStringIO (json .dumps (self .response ))
674
+
675
+ from WmAgentScripts .utils import getWorkflowByCampaign
676
+
677
+ with patch ('WmAgentScripts.utils.make_x509_conn' , MockResponseStringIo ):
678
+ response = getWorkflowByCampaign (
679
+ url = 'http://someurl.com/' ,
680
+ campaign = 'somecampaign' ,
681
+ details = False
682
+ )
683
+ self .assertEqual (
684
+ response , [{'data' : [{'name' : 'someSite' }, {'name' : 'someSite1' }]}])
685
+
686
+ response = getWorkflowByCampaign (
687
+ url = 'http://someurl.com/' ,
688
+ campaign = 'somecampaign' ,
689
+ details = True
690
+ )
691
+ self .assertEqual (
692
+ response , [[{'name' : 'someSite' }, {'name' : 'someSite1' }]])
693
+
694
+
640
695
if __name__ == '__main__' :
641
696
unittest .main ()
0 commit comments