Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit d0f4cd4

Browse files
committed
add unittests for utils.getWorkflowByCampaign
1 parent e4a0ce8 commit d0f4cd4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/test_utils.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ def test_is_json(self):
408408
class TestReadFile(unittest.TestCase):
409409

410410
def test_read_file(self):
411+
411412
from WmAgentScripts.utils import read_file
412413
test_json = {
413414
"first": {"a": "A"},
@@ -452,7 +453,9 @@ def getresponse(self):
452453
class TestCheckTransferApproval(unittest.TestCase):
453454

454455
def test_checkTransferApproval(self):
456+
455457
class MockResponseStringIo:
458+
456459
def __init__(self, *args, **kwargs):
457460
self.response = None
458461

@@ -490,7 +493,9 @@ def getresponse(self):
490493
class TestGetNodesId(unittest.TestCase):
491494

492495
def test_getNodesId(self):
496+
493497
class MockResponseStringIo:
498+
494499
def __init__(self, *args, **kwargs):
495500
self.response = None
496501

@@ -524,7 +529,9 @@ def getresponse(self):
524529

525530

526531
class TestGetDatasetFileLocations(unittest.TestCase):
532+
527533
def test_getDatasetFileLocations(self):
534+
528535
class MockResponseStringIo:
529536
def __init__(self, *args, **kwargs):
530537
self.response = None
@@ -553,12 +560,15 @@ def request(self, *args, **kwargs):
553560

554561
def getresponse(self):
555562
return ContextualStringIO(json.dumps(self.response))
563+
556564
from WmAgentScripts.utils import getDatasetFileLocations
565+
557566
with patch('WmAgentScripts.utils.make_x509_conn', MockResponseStringIo):
558567
response = getDatasetFileLocations(
559568
url='http://someurl.com/',
560569
dataset='somedataset'
561570
)
571+
562572
self.assertDictEqual(
563573
response, {
564574
'someSite': set(['someNode']),
@@ -637,5 +647,50 @@ def test_getConfigurationLine(self):
637647
self.assertEqual(response, "Test2 line 2")
638648

639649

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+
640695
if __name__ == '__main__':
641696
unittest.main()

0 commit comments

Comments
 (0)