Skip to content

Commit ec33a76

Browse files
committed
fix more comments
1 parent 28e1111 commit ec33a76

File tree

3 files changed

+96
-18
lines changed

3 files changed

+96
-18
lines changed

facturapi/resources/invoices.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,10 @@ def send_by_email(
216216
ValueError: If the invoice_id is not provided.
217217
requests.RequestException: If the API request fails.
218218
"""
219-
if not invoice_id:
220-
raise ValueError("The invoice_id is required to send by email.")
221219

222220
endpoint = f"{cls._resource}/{invoice_id}/email"
223221
payload = {}
224-
if isinstance(recipients, (str, list)):
222+
if recipients:
225223
payload["email"] = recipients
226224
response = client.post(endpoint, payload)
227225
return response.get("ok", False)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
interactions:
2+
- request:
3+
body: '{}'
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Authorization:
10+
- DUMMY
11+
Connection:
12+
- keep-alive
13+
Content-Length:
14+
- '2'
15+
Content-Type:
16+
- application/json
17+
User-Agent:
18+
- facturapi-python/0.2.0
19+
method: POST
20+
uri: https://www.facturapi.io/v2/invoices/INVOICE_NOT_FOUND/email
21+
response:
22+
body:
23+
string: '{"message":"Invoice with Id \"INVOICE_NOT_FOUND\" was not found or
24+
you don''t have the right permissions","ok":false}'
25+
headers:
26+
Content-Length:
27+
- '116'
28+
access-control-allow-origin:
29+
- '*'
30+
content-security-policy:
31+
- 'default-src ''self'' https://accounts.google.com/gsi/* https://*.stripe.com;font-src
32+
https:;img-src data: https: https://*.stripe.com;script-src ''unsafe-inline''
33+
https: https://accounts.google.com/gsi/client https://builder.io https://builder.io/*;style-src
34+
https: ''unsafe-inline'' https://accounts.google.com/gsi/style;base-uri ''self'';object-src
35+
''none'';connect-src https: https://accounts.google.com/gsi/* https://*.stripe.com;frame-src
36+
''self'' *.stripe.com *.facebook.com https://accounts.google.com/ https://accounts.google.com/gsi/
37+
https://accounts.google.com/gsi/* https://builder.io https://builder.io/*;frame-ancestors
38+
''self'' https://builder.io https://builder.io/*;upgrade-insecure-requests;form-action
39+
''self'';script-src-attr ''none'''
40+
content-type:
41+
- application/json; charset=utf-8
42+
cross-origin-opener-policy:
43+
- same-origin-allow-popups
44+
cross-origin-resource-policy:
45+
- same-site
46+
date:
47+
- Fri, 04 Apr 2025 02:59:28 GMT
48+
etag:
49+
- W/"74-9U2JIE0F589sz9k6Zf4ELoiLoa4"
50+
origin-agent-cluster:
51+
- ?1
52+
referrer-policy:
53+
- no-referrer
54+
server:
55+
- Google Frontend
56+
strict-transport-security:
57+
- max-age=15552000; includeSubDomains
58+
x-cloud-trace-context:
59+
- 34e5c1b94a06826421ee52ae05c02139/10885945258051611867;o=1
60+
x-content-type-options:
61+
- nosniff
62+
x-dns-prefetch-control:
63+
- 'off'
64+
x-download-options:
65+
- noopen
66+
x-facturapi-log-id:
67+
- 67ef4b105eb1f5f4a053ae9f
68+
x-frame-options:
69+
- SAMEORIGIN
70+
x-permitted-cross-domain-policies:
71+
- none
72+
x-xss-protection:
73+
- '0'
74+
status:
75+
code: 400
76+
message: Bad Request
77+
version: 1

tests/resources/test_invoices.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
from facturapi.resources.customers import CustomerRequest
55
from facturapi.resources.invoices import InvoiceRequest
66
from facturapi.types import FileType, PaymentForm
7-
from facturapi.types.exc import MultipleResultsFound, NoResultFound
7+
from facturapi.types.exc import (
8+
FacturapiResponseException,
9+
MultipleResultsFound,
10+
NoResultFound,
11+
)
812
from facturapi.types.general import CustomerAddress, ItemPart
913

1014

@@ -107,36 +111,35 @@ def test_cancel_invoice():
107111
@pytest.mark.vcr
108112
def test_send_invoice_by_email_without_email():
109113
invoice_id = "67e59a55f4f823d3d978f3cb"
110-
resp = facturapi.Invoice.send_by_email(invoice_id=invoice_id)
111-
112-
assert resp is True
114+
email_sent = facturapi.Invoice.send_by_email(invoice_id=invoice_id)
115+
assert email_sent
113116

114117

115118
@pytest.mark.vcr
116119
def test_send_invoice_by_email_with_email():
117120
invoice_id = "67e59a55f4f823d3d978f3cb"
118121
email = "frida_kahlo@test.com"
119122
recipients = [email]
120-
resp = facturapi.Invoice.send_by_email(
123+
email_sent = facturapi.Invoice.send_by_email(
121124
invoice_id=invoice_id, recipients=recipients
122125
)
123-
124-
assert resp is True
126+
assert email_sent
125127

126128

127129
@pytest.mark.vcr
128130
def test_send_invoice_by_email_false():
129131
invoice_id = "INVOICE01"
130-
resp = facturapi.Invoice.send_by_email(invoice_id=invoice_id)
132+
email_sent = facturapi.Invoice.send_by_email(invoice_id=invoice_id)
133+
assert not email_sent
131134

132-
assert resp is False
133135

134-
135-
def test_send_invoice_by_email_missing_invoice_id():
136-
with pytest.raises(
137-
ValueError, match="The invoice_id is required to send by email."
138-
):
139-
facturapi.Invoice.send_by_email(invoice_id=None)
136+
@pytest.mark.vcr
137+
def test_send_invoice_by_email_invoice_not_found():
138+
invoice_id = "INVOICE_NOT_FOUND"
139+
with pytest.raises(FacturapiResponseException) as exc_info:
140+
facturapi.Invoice.send_by_email(invoice_id=invoice_id)
141+
exc_str = str(exc_info.value)
142+
assert f'Invoice with Id "{invoice_id}" was not found' in exc_str
140143

141144

142145
@pytest.mark.vcr

0 commit comments

Comments
 (0)