def test_simple_case(self):
ticket_url = "http://ticket.com"
data_url = "http://data.url.com"
headers = {"a": "a", "xyz": "ghj"}
ticket = {"htsget": {
"urls": [{"url": data_url, "headers": headers}]}}
data = b"0" * 1024
returned_response = MockedResponse(json.dumps(ticket).encode(), data)
with mock.patch("requests.get", return_value=returned_response) as mocked_get:
with tempfile.NamedTemporaryFile("wb+") as f:
htsget.get(ticket_url, f)
f.seek(0)
self.assertEqual(f.read(), data)
self.assertEqual(mocked_get.call_count, 2)
# Note that we only get the arguments for the last call using this method.
args, kwargs = mocked_get.call_args
self.assertEqual(args[0], data_url)
self.assertEqual(kwargs["headers"], headers)
self.assertEqual(kwargs["stream"], True)
评论列表
文章目录