[IMP] docuseal_signing: add unit tests for API payload and server action
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m28s
tests / test (pull_request) Successful in 51s

Cover with a mocked Docuseal API (shared ``DocusealApiMockMixin``
capturing every request):

- field value conversion matrix in ``_create_submissions``: char,
  selection label, many2one/many2many display names, date formatting,
  empty value left editable while set values are locked
- payload structure and one-submission-per-partner behavior
- draft submissions created with ``send_email`` disabled
- API URL trailing slash stripped
- server action creation is idempotent

Assisted-By: GLM-5.3-Flash
This commit is contained in:
2026-11-03 17:25:54 +01:00
parent 5050219d8c
commit f9a8358e95
5 changed files with 199 additions and 35 deletions

View File

@@ -1,13 +1,9 @@
import json
from unittest import mock
from odoo.addons.docuseal_signing.models import (
docuseal_template as docuseal_template_module,
)
from odoo.tests import TransactionCase
from .common import DocusealApiMockMixin
class TestFetchFields(TransactionCase):
class TestFetchFields(DocusealApiMockMixin, TransactionCase):
"""Reconciliation of the field mapping on action_fetch_fields."""
@classmethod
@@ -31,14 +27,6 @@ class TestFetchFields(TransactionCase):
"docuseal_field_name": "obsolete",
})
def _mock_urlopen(self, payload):
resp = mock.MagicMock()
resp.read.return_value = json.dumps(payload).encode()
context_manager = mock.MagicMock()
context_manager.__enter__.return_value = resp
context_manager.__exit__.return_value = False
return context_manager
def test_fetch_fields_reconciles_mapping(self):
"""Existing mappings keep their partner field; removed Docuseal
fields are dropped and new ones are added, in the order returned
@@ -48,11 +36,7 @@ class TestFetchFields(TransactionCase):
"submitters": [{"name": "Signer"}],
"fields": [{"name": "phone"}, {"name": "extra"}, {"name": ""}],
}
with mock.patch.object(
docuseal_template_module.urllib.request,
"urlopen",
return_value=self._mock_urlopen(payload),
):
with self._mock_api(payload):
self.template.action_fetch_fields()
names = {
@@ -84,11 +68,7 @@ class TestFetchFields(TransactionCase):
"submitters": [{"name": "Counterparty"}],
"fields": [],
}
with mock.patch.object(
docuseal_template_module.urllib.request,
"urlopen",
return_value=self._mock_urlopen(payload),
):
with self._mock_api(payload):
self.template.action_fetch_fields()
self.assertEqual(self.template.name, "Contract")
@@ -102,11 +82,7 @@ class TestFetchFields(TransactionCase):
"submitters": [{"name": "Signer"}],
"fields": [{"name": "a"}, {"name": "b"}, {"name": "c"}],
}
with mock.patch.object(
docuseal_template_module.urllib.request,
"urlopen",
return_value=self._mock_urlopen(payload),
):
with self._mock_api(payload):
self.template.action_fetch_fields()
self.assertEqual(
self.template.field_ids.mapped("docuseal_field_name"),
@@ -119,11 +95,7 @@ class TestFetchFields(TransactionCase):
# Re-fetching must restore the Docuseal order. Invalidate the
# one2many cache to read like a fresh request would (the web
# client always re-reads after the action).
with mock.patch.object(
docuseal_template_module.urllib.request,
"urlopen",
return_value=self._mock_urlopen(payload),
):
with self._mock_api(payload):
self.template.action_fetch_fields()
self.template.invalidate_recordset(["field_ids"])
self.assertEqual(