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

Commit 69ebbf5

Browse files
committed
add unittests for utils.listRequests
1 parent c0cb866 commit 69ebbf5

1 file changed

Lines changed: 49 additions & 19 deletions

File tree

tests/test_utils.py

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
import mock
66
from mock import MagicMock, patch, mock_open
77

8+
from StringIO import StringIO
9+
10+
11+
class ContextualStringIO(StringIO):
12+
def __enter__(self):
13+
return self
14+
15+
def __exit__(self, *args):
16+
self.close()
17+
return False
18+
819

920
class TestDeepUpdate(unittest.TestCase):
1021

@@ -122,16 +133,6 @@ def getresponse(self):
122133

123134
def test_get_json_object(self):
124135

125-
from StringIO import StringIO
126-
127-
class ContextualStringIO(StringIO):
128-
def __enter__(self):
129-
return self
130-
131-
def __exit__(self, *args):
132-
self.close()
133-
return False
134-
135136
class MockResponseStringIo:
136137
def __init__(self, *args, **kwargs):
137138
self.response = None, 404
@@ -170,15 +171,6 @@ def getresponse(self):
170171
class TestGetSubscription(unittest.TestCase):
171172

172173
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
182174

183175
class MockResponseStringIo:
184176
def __init__(self, *args, **kwargs):
@@ -198,5 +190,43 @@ def getresponse(self):
198190
self.assertEqual(response, "value1")
199191

200192

193+
class TestListRequests(unittest.TestCase):
194+
195+
def testListRequests(self):
196+
197+
class MockResponseStringIo:
198+
def __init__(self, *args, **kwargs):
199+
self.response = None, 404
200+
201+
def request(self, *args, **kwargs):
202+
self.response = {"phedex": {
203+
"request": [{
204+
"node": [
205+
{"name": "someSite"},
206+
{"name": "someSite1"}
207+
],
208+
"id": "someId"
209+
}]}
210+
}
211+
212+
def getresponse(self):
213+
return ContextualStringIO(json.dumps(self.response))
214+
215+
from WmAgentScripts.utils import listRequests
216+
with patch('WmAgentScripts.utils.make_x509_conn', MockResponseStringIo):
217+
response = listRequests(
218+
url='http://someurl.com/',
219+
dataset="somedataset",
220+
site=None)
221+
self.assertDictEqual(
222+
response, {
223+
'someSite1': ['someId'], 'someSite': ['someId']})
224+
response = listRequests(
225+
url='http://someurl.com/',
226+
dataset="somedataset",
227+
site='someSite')
228+
self.assertDictEqual(response, {'someSite': ['someId']})
229+
230+
201231
if __name__ == '__main__':
202232
unittest.main()

0 commit comments

Comments
 (0)