Commit ec1b056d by Calen Pennington

Use requests library utility method for getting json results

parent cb93b665
...@@ -109,26 +109,18 @@ def make_mock_request_impl(text, thread_id=None): ...@@ -109,26 +109,18 @@ def make_mock_request_impl(text, thread_id=None):
def mock_request_impl(*args, **kwargs): def mock_request_impl(*args, **kwargs):
url = args[1] url = args[1]
if url.endswith("threads"): if url.endswith("threads"):
return Mock( data = {
status_code=200, "collection": [make_mock_thread_data(text, "dummy_thread_id", False)]
text=json.dumps({ }
"collection": [make_mock_thread_data(text, "dummy_thread_id", False)]
})
)
elif thread_id and url.endswith(thread_id): elif thread_id and url.endswith(thread_id):
return Mock( data = make_mock_thread_data(text, thread_id, True)
status_code=200,
text=json.dumps(make_mock_thread_data(text, thread_id, True))
)
else: # user query else: # user query
return Mock( data = {
status_code=200, "upvoted_ids": [],
text=json.dumps({ "downvoted_ids": [],
"upvoted_ids": [], "subscribed_thread_ids": [],
"downvoted_ids": [], }
"subscribed_thread_ids": [], return Mock(status_code=200, text=json.dumps(data), json=Mock(return_value=data))
})
)
return mock_request_impl return mock_request_impl
......
...@@ -87,7 +87,7 @@ def perform_request(method, url, data_or_params=None, raw=False): ...@@ -87,7 +87,7 @@ def perform_request(method, url, data_or_params=None, raw=False):
if raw: if raw:
return response.text return response.text
else: else:
return json.loads(response.text) return response.json()
class CommentClientError(Exception): class CommentClientError(Exception):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment