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

Commit c0cb866

Browse files
committed
add unittests for utils.getSubscriptions
1 parent ae38d3e commit c0cb866

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,36 @@ def getresponse(self):
167167
self.assertEqual([None, 404], response)
168168

169169

170+
class TestGetSubscription(unittest.TestCase):
171+
172+
def testGetSubscription(self):
173+
from StringIO import StringIO
174+
175+
class ContextualStringIO(StringIO):
176+
def __enter__(self):
177+
return self
178+
179+
def __exit__(self, *args):
180+
self.close()
181+
return False
182+
183+
class MockResponseStringIo:
184+
def __init__(self, *args, **kwargs):
185+
self.response = None, 404
186+
187+
def request(self, *args, **kwargs):
188+
self.response = {"phedex": "value1"}
189+
190+
def getresponse(self):
191+
return ContextualStringIO(json.dumps(self.response))
192+
193+
from WmAgentScripts.utils import getSubscriptions
194+
with patch('WmAgentScripts.utils.make_x509_conn', MockResponseStringIo):
195+
response = getSubscriptions(
196+
url='http://someurl.com/',
197+
dataset="somedataset")
198+
self.assertEqual(response, "value1")
199+
200+
170201
if __name__ == '__main__':
171202
unittest.main()

0 commit comments

Comments
 (0)