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}})
"""


def Response(*args, **kwargs):
    return type('Response', (), {'raise_for_status': object})


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())
            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',
                    },
                ],
            )
