TEST Data
Use client.testdata only in Environment.TEST. These helpers mutate sandbox
data so your tests and demos can create known contexts.
Create and clean up manually
Section titled “Create and clean up manually”client.testdata.create_subject( nip="5261040828", subject_type="vat_group", description="Sandbox company",)
client.testdata.enable_attachments(nip="5261040828")
client.testdata.delete_subject(nip="5261040828")Use temporal cleanup
Section titled “Use temporal cleanup”The temporal helper records mutations and attempts cleanup when the block exits.
with client.testdata.temporal() as data: data.create_subject( nip="5261040828", subject_type="vat_group", description="Integration test subject", ) data.enable_attachments(nip="5261040828")from ksef2.domain.models import Identifier, Permission
with client.testdata.temporal() as data: data.grant_permissions( permissions=[Permission(type="invoice_read", description="Read invoices")], grant_to=Identifier(type="nip", value="1111111111"), in_context_of=Identifier(type="nip", value="5261040828"), )Recommended flow
Section titled “Recommended flow”-
Create subjects, people, permissions, or attachment flags required by a test.
-
Use
temporal()for fixtures that should be cleaned up automatically. -
Use direct create/delete methods when setup is shared across many test runs.
-
Keep generated identifiers in test config, not production config.