Skip to content

Commit c43c30a

Browse files
committed
fix: download response bug
1 parent 9f61f75 commit c43c30a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/pyinterboleto/consulta/pdf.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from requests import get
66

77
from ..auth import get_api_configs
8+
from ..exceptions import PyInterBoletoException
89
from ..utils.requests import PathType, RequestConfigs
910
from ..utils.url import API_URL
1011

@@ -45,9 +46,12 @@ def get_pdf_boleto_in_memory(
4546
response = get(URL, headers=headers, cert=(certificate, key))
4647

4748
if response.status_code != 200:
48-
raise ValueError("Não foi possível resgatar as informações do boleto.")
49+
raise PyInterBoletoException(
50+
"Não foi possível resgatar as informações do boleto."
51+
)
4952

50-
return BytesIO(b64decode(response.content))
53+
raw_bytes = b64decode(response.json()["pdf"])
54+
return BytesIO(raw_bytes)
5155

5256

5357
def get_pdf_boleto_to_file(

tests/query/detail.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def test_pdf(request_configs: RequestConfigs, patched_auth_request: Mock):
7070
with patch("src.pyinterboleto.consulta.pdf.get") as patched_get:
7171
mocked_reponse = Mock()
7272
mocked_reponse.status_code = 200
73-
mocked_reponse.content = b64encode("some dummy pdf.data".encode("utf-8"))
73+
mocked_reponse.json = Mock(
74+
return_value={"pdf": b64encode("some dummy pdf.data".encode("utf-8"))}
75+
)
7476
patched_get.return_value = mocked_reponse
7577

7678
boleto.consulta_pdf("01234567891")

0 commit comments

Comments
 (0)