114 lines
3.3 KiB
Python
114 lines
3.3 KiB
Python
import base64
|
|
import uuid
|
|
from unittest.mock import patch
|
|
|
|
from docuseal import create_submission_from_pdf
|
|
|
|
SUBJECT = '{first_name}, assine seu certificado agora!'
|
|
MESSAGE = """
|
|
{first_name},
|
|
Seu certificado já está pronto e aguardando apenas a sua assinatura digital.
|
|
|
|
[👉 Assinar agora.]({{submitter.link}})
|
|
"""
|
|
|
|
|
|
doc = {
|
|
'id': 549,
|
|
'name': '7dc7005e-0b98-4e79-b1d1-17999b7555e7',
|
|
'submitters': [
|
|
{
|
|
'id': 549,
|
|
'slug': 'CPZ92dWCMVUbD5',
|
|
'uuid': 'b57b1504-2c16-412e-96a4-1e555bff1cce',
|
|
'name': 'Sérgio R Siqueira',
|
|
'email': 'sergio@somosbeta.com.br',
|
|
'phone': None,
|
|
'completed_at': None,
|
|
'declined_at': None,
|
|
'external_id': None,
|
|
'submission_id': 549,
|
|
'metadata': {},
|
|
'opened_at': None,
|
|
'sent_at': '2025-12-23T23:02:03.491Z',
|
|
'created_at': '2025-12-23T23:02:03.496Z',
|
|
'updated_at': '2025-12-23T23:02:03.496Z',
|
|
'status': 'sent',
|
|
'application_key': None,
|
|
'values': [],
|
|
'preferences': {
|
|
'email_message_uuid': 'f53c861b-d851-46bc-bcae-e7260fdcff3c',
|
|
'send_email': True,
|
|
'send_sms': False,
|
|
},
|
|
'role': 'First Party',
|
|
'embed_src': 'https://docs.eduseg.com.br/s/CPZ92dWCMVUbD5',
|
|
}
|
|
],
|
|
'source': 'api',
|
|
'submitters_order': 'preserved',
|
|
'status': 'pending',
|
|
'schema': [
|
|
{
|
|
'name': '7dc7005e-0b98-4e79-b1d1-17999b7555e7',
|
|
'attachment_uuid': '64bde5ce-327a-4a0d-9923-2b0c91028e71',
|
|
}
|
|
],
|
|
'fields': [
|
|
{
|
|
'name': 'Assinatura',
|
|
'type': 'signature',
|
|
'default_value': None,
|
|
'conditions': None,
|
|
'required': True,
|
|
'uuid': '2bbae88a-8a00-4f71-bdc0-edcce154252c',
|
|
'submitter_uuid': 'b57b1504-2c16-412e-96a4-1e555bff1cce',
|
|
'areas': [
|
|
{
|
|
'page': 0,
|
|
'attachment_uuid': '64bde5ce-327a-4a0d-9923-2b0c91028e71',
|
|
'x': 0.08876572705307295,
|
|
'y': 0.6920383425296537,
|
|
'w': 0.1995770152872413,
|
|
'h': 0.04878657103210542,
|
|
}
|
|
],
|
|
}
|
|
],
|
|
'expire_at': None,
|
|
'created_at': '2025-12-23T23:02:03.493Z',
|
|
}
|
|
|
|
|
|
def Response(*args, **kwargs):
|
|
return type(
|
|
'Response',
|
|
(),
|
|
{
|
|
'raise_for_status': object,
|
|
'json': lambda: doc,
|
|
},
|
|
)
|
|
|
|
|
|
def test_create_submission_from_pdf():
|
|
with patch('docuseal.requests.post', Response):
|
|
with open('tests/sample.pdf', 'rb') as f:
|
|
file = base64.b64encode(f.read())
|
|
r = create_submission_from_pdf(
|
|
str(uuid.uuid4()),
|
|
file=file.decode('utf-8'),
|
|
email_message={
|
|
'subject': SUBJECT.format(first_name='Tiago'),
|
|
'body': MESSAGE.format(first_name='Tiago'),
|
|
},
|
|
submitters=[
|
|
{
|
|
'role': 'Aluno',
|
|
'name': 'Sérgio R Siqueira',
|
|
'email': 'sergio@somosbeta.com.br',
|
|
},
|
|
],
|
|
)
|
|
assert 'name' in r
|