aeat.adapters.outbound.aeat.verify package¶
Read-only CSV verification against AEAT’s Sede electrónica.
The verify_csv() helper is opt-in: it only runs when the caller supplies
or constructs a adapters.outbound.aeat.browser.DefaultBrowserSession.
It is guarded by domain.calculations.registry.RemoteStateGuardPolicy
and never mutates AEAT-side state. The contract is:
open the Sede verification page,
enter the CSV,
read back the server response,
return
Trueiff AEAT confirms the document as valid.
The function degrades gracefully when a browser cannot be
constructed and surfaces the underlying error to the caller via
domain.justificante.JustificanteVerificationError.
Public surface: verify_csv() plus the Playwright protocol
types (VerifyBrowserKeyboardLike, VerifyBrowserPageLike,
VerifyBrowserContextLike, VerifyBrowserSessionLike,
VerifyBrowserSessionFactory) that let the helper be unit-tested
without spinning up a real browser.
See also
adapters.outbound.aeat.browser.default_browser_session_factory()Production factory used by
DEFAULT_BROWSER_SESSION_FACTORY.adapters.outbound.aeat.browser.BrowserSessionConcrete browser session whose context/page surface these protocols mirror.
domain.calculations.registry.assert_remote_operation_allowed()Guard used to allow only the reviewed read-only CSV verification URL and browser action token.
- class VerifyBrowserKeyboardLike(*args, **kwargs)[source]¶
Bases:
ProtocolSubset of Playwright’s
KeyboardAPI used byverify_csv().The protocol keeps the fallback query path testable without importing a concrete Playwright
Keyboardat runtime.
- class VerifyBrowserPageLike(*args, **kwargs)[source]¶
Bases:
ProtocolSubset of Playwright’s
PageAPI used byverify_csv().The page surface is intentionally small: navigation to the reviewed Sede URL, CSV entry through a selector or keyboard fallback, and HTML content capture for the confirmation-token parse.
-
keyboard:
VerifyBrowserKeyboardLike¶
-
keyboard:
- class VerifyBrowserContextLike(*args, **kwargs)[source]¶
Bases:
ProtocolSubset of Playwright’s
BrowserContextAPI used byverify_csv().Context ownership depends on the caller:
verify_csv()always closes the context it opens, while the surrounding session is closed only when the helper created it throughDEFAULT_BROWSER_SESSION_FACTORY.- async new_page()[source]¶
Open a new
VerifyBrowserPageLikewithin this browser context.- Return type:
- class VerifyBrowserSessionLike(*args, **kwargs)[source]¶
Bases:
ProtocolBrowser-session surface consumed by
verify_csv().The
create_contextsignature mirrorsadapters.outbound.aeat.browser.BrowserSession.create_context()so static checkers see no unsafe overlap between this protocol and the concrete browser sessions.verify_csvitself callscreate_context()with no arguments; production and test sessions accept the same optional kwargs as the centraladapters.outbound.aeat.browser.BrowserSessionso the protocol stays structurally honest.- async create_context(*, provisioner=None, storage_state_path=None, storage_state=None)[source]¶
Create and return a configured
VerifyBrowserContextLike.- Return type:
- Parameters:
- VerifyBrowserSessionFactory¶
Callable that builds a self-owned
VerifyBrowserSessionLike.alias of
Callable[[],Awaitable[VerifyBrowserSessionLike]]
- async DEFAULT_BROWSER_SESSION_FACTORY(factory=None)¶
Module-level factory seam for the self-owned
verify_csv()path.- Return type:
- Parameters:
- async verify_csv(csv, *, browser=None, browser_session_factory=None)[source]¶
Verify a justificante CSV against AEAT’s Sede electrónica.
The helper normalises the CSV, opens the reviewed public Sede verification URL under the read-only guard, submits the CSV, and parses the returned HTML for AEAT confirmation tokens. Passing
browserborrows the session from the caller; omitting it builds a self-owned session throughbrowser_session_factoryorDEFAULT_BROWSER_SESSION_FACTORYand closes that session after the round-trip.- Parameters:
csv (
str) – The Código Seguro de Verificación as printed on the receipt.browser (
VerifyBrowserSessionLike|None) – An already-constructedVerifyBrowserSessionLike. WhenNone, one is built from the default settings/profile.browser_session_factory (
Callable[[],Awaitable[VerifyBrowserSessionLike]] |None) – Optional no-argument factory for the self-owned path. Ignored whenbrowseris supplied.
- Return type:
- Returns:
Trueif AEAT confirms the CSV as valid;Falseif AEAT reports the document as unknown.- Raises:
JustificanteVerificationError – If the round-trip cannot be completed because browser construction, navigation, the guard, or parsing fails.