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

Commit 5efcfef

Browse files
committed
add unittests for utils.checkDownTime
1 parent f36e6b0 commit 5efcfef

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/test_utils.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,41 @@ def getresponse(self):
352352
self.assertFalse(response)
353353

354354

355+
class TesCheckDownTime(unittest.TestCase):
356+
357+
def testCheckDownTime(self):
358+
359+
class MockResponseStringIo(StringIO):
360+
status = 503
361+
362+
def __enter__(self):
363+
return self
364+
365+
def __exit__(self, *args):
366+
self.close()
367+
return False
368+
369+
class MockResponse:
370+
def __init__(self, *args, **kwargs):
371+
self.response = None
372+
373+
def request(self, *args, **kwargs):
374+
self.response = {}
375+
376+
def getresponse(self):
377+
return MockResponseStringIo(json.dumps(self.response))
378+
379+
from WmAgentScripts.utils import checkDownTime
380+
381+
with patch('WmAgentScripts.utils.make_x509_conn', MockResponse):
382+
response = checkDownTime()
383+
self.assertTrue(response)
384+
385+
MockResponseStringIo.status = 404
386+
with patch('WmAgentScripts.utils.make_x509_conn', MockResponse):
387+
response = checkDownTime()
388+
self.assertFalse(response)
389+
390+
355391
if __name__ == '__main__':
356392
unittest.main()

0 commit comments

Comments
 (0)