def test_bearer_token(self):
ticket_url = "http://ticket.com"
ticket = {"htsget": {"urls": []}}
bearer_token = "x" * 1024
returned_response = MockedTicketResponse(json.dumps(ticket).encode())
with mock.patch("requests.get", return_value=returned_response) as mocked_get:
with tempfile.NamedTemporaryFile("wb+") as f:
htsget.get(ticket_url, f, bearer_token=bearer_token)
f.seek(0)
self.assertEqual(f.read(), b"")
# Because we have no URLs in the returned ticked, it should be called
# only once.
self.assertEqual(mocked_get.call_count, 1)
# Note that we only get the arguments for the last call using this method.
args, kwargs = mocked_get.call_args
self.assertEqual(args[0], ticket_url)
headers = {"Authorization": "Bearer {}".format(bearer_token)}
self.assertEqual(kwargs["headers"], headers)
self.assertEqual(kwargs["stream"], True)
评论列表
文章目录