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

Commit 141c909

Browse files
committed
add unittests for utils.getDatasetFileLocations
1 parent eea926f commit 141c909

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/test_utils.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,5 +523,48 @@ def getresponse(self):
523523
'someSite1': 'someId1'})
524524

525525

526+
class TestGetDatasetFileLocations(unittest.TestCase):
527+
def test_getDatasetFileLocations(self):
528+
class MockResponseStringIo:
529+
def __init__(self, *args, **kwargs):
530+
self.response = None
531+
532+
def request(self, *args, **kwargs):
533+
self.response = {"phedex": {
534+
"block": [{
535+
"file": [
536+
{
537+
"name": "someSite",
538+
"decision": "approved",
539+
"replica": [{
540+
"node": "someNode"
541+
}]
542+
},
543+
{
544+
"name": "someSite1",
545+
"decision": "pending",
546+
"replica": [{
547+
"node": "someNode1"
548+
}]
549+
},
550+
],
551+
}]}
552+
}
553+
554+
def getresponse(self):
555+
return ContextualStringIO(json.dumps(self.response))
556+
from WmAgentScripts.utils import getDatasetFileLocations
557+
with patch('WmAgentScripts.utils.make_x509_conn', MockResponseStringIo):
558+
response = getDatasetFileLocations(
559+
url='http://someurl.com/',
560+
dataset='somedataset'
561+
)
562+
print response
563+
self.assertDictEqual(
564+
response, {
565+
'someSite': set(['someNode']),
566+
'someSite1': set(['someNode1'])})
567+
568+
526569
if __name__ == '__main__':
527570
unittest.main()

0 commit comments

Comments
 (0)