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

Commit 56858c5

Browse files
committed
add unittests for utils.invalidateFiles
1 parent 141c909 commit 56858c5

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/test_utils.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,43 @@ def getresponse(self):
559559
url='http://someurl.com/',
560560
dataset='somedataset'
561561
)
562-
print response
563562
self.assertDictEqual(
564563
response, {
565564
'someSite': set(['someNode']),
566565
'someSite1': set(['someNode1'])})
567566

568567

568+
class TestInvalidateFiles(unittest.TestCase):
569+
570+
def test_invalidateFiles(self):
571+
572+
class MockResponseStringIo:
573+
response = {"result": "OK"}
574+
575+
def __init__(self, *args, **kwargs):
576+
pass
577+
578+
def request(self, *args, **kwargs):
579+
pass
580+
581+
def getresponse(self):
582+
return ContextualStringIO(json.dumps(self.response))
583+
584+
from WmAgentScripts.utils import invalidateFiles
585+
586+
with patch('WmAgentScripts.utils.httplib.HTTPSConnection', MockResponseStringIo):
587+
response = invalidateFiles(
588+
files=["file1", "file2"],
589+
)
590+
self.assertTrue(response)
591+
592+
MockResponseStringIo.response = {"result": "Not OK"}
593+
with patch('WmAgentScripts.utils.httplib.HTTPSConnection', MockResponseStringIo):
594+
response = invalidateFiles(
595+
files=["file1", "file2"],
596+
)
597+
self.assertFalse(response)
598+
599+
569600
if __name__ == '__main__':
570601
unittest.main()

0 commit comments

Comments
 (0)