File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
src/pyinterboleto/consulta Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change 55from requests import get
66
77from ..auth import get_api_configs
8+ from ..exceptions import PyInterBoletoException
89from ..utils .requests import PathType , RequestConfigs
910from ..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
5357def get_pdf_boleto_to_file (
Original file line number Diff line number Diff 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" )
You can’t perform that action at this time.
0 commit comments