test_io.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:htsget 作者: jeromekelleher 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号