You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/architecture.rst
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ System components
9
9
10
10
wagtail-factories extends Factory Boy to create test data for Wagtail CMS models. The system consists of three main layers:
11
11
12
-
**Factory layer**
12
+
**Model factory layer**
13
13
Core factory classes that extend Factory Boy's ``DjangoModelFactory`` for Wagtail-specific models (``PageFactory``, ``ImageFactory``, etc.)
14
14
15
15
**Block factory layer**
@@ -85,7 +85,7 @@ StreamField factories are defined using class-based syntax that mirrors Wagtail'
85
85
class Meta:
86
86
model = MyStreamBlock
87
87
88
-
This approach enables nested StreamBlocks, better IDE support, and cleaner factory composition.
88
+
This approach enables nested StreamBlocks and clean, introspectable factory composition.
89
89
90
90
.. note::
91
91
@@ -156,4 +156,8 @@ This allows adaptation to domain-specific Wagtail block types while maintaining
156
156
Next steps
157
157
==========
158
158
159
-
**For contributors**: If you need to modify or extend the StreamField factory system, see :doc:`streamfield-internals` for detailed technical implementation details including Factory Boy integration mechanisms, parameter parsing, and builder system architecture.
159
+
**For contributors**: If you need to modify or extend the StreamField factory system, see :doc:`streamfield-internals` for detailed technical implementation details, including:
@@ -194,7 +196,7 @@ When a StreamBlock contains multiple instances of the same block type (e.g., ``0
194
196
Factory Boy DeclarationSet compatibility
195
197
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196
198
197
-
Factory Boy uses a DeclarationSet to store factory attributes like ``title = "Hello"``. Each key must be unique and hashable. Using ``0.struct_block__title`` as the key allows the system to associate parameters with the correct generated factory field during dynamic factory creation.
199
+
Factory Boy uses a DeclarationSet to store factory attributes like ``title = "Hello"``. Each key must be unique and hashable. Using ``0.struct_block__title`` as the key allows the system to associate parameters with the correct generated factory field during dynamic factory creation (see `Phase 2: Generate a Factory class dynamically`_).
198
200
199
201
Prevents Factory Boy field interpretation errors
200
202
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -293,7 +295,7 @@ Factory Boy handles the initial parameter filtering automatically. The ``Paramet
293
295
294
296
1. User calls ``MyPageFactory(body__0__struct_block__title="foo")``
295
297
2. Factory Boy processes: Identifies ``body__`` prefix matches ``StreamFieldFactory``
296
-
3. Factory Boy strips: Removes ``body__`` prefix from matching parameters
298
+
3. Factory Boy strips: Removes ``body__`` prefix from matching parameters
@@ -623,7 +625,7 @@ Specialized options for StreamBlock factories with advanced parameter filtering:
623
625
block_name = get_block_name(k)
624
626
if (
625
627
block_name notinself.exclude
626
-
and block_name notinself.parameters
628
+
and block_name notinself.parameters
627
629
and v isnot declarations.SKIP
628
630
):
629
631
filtered_kwargs[k] = v
@@ -663,21 +665,21 @@ Explicit block definition
663
665
block_def = MyStreamBlock() # Explicit
664
666
665
667
Auto-instantiation (more common)
666
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
668
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
667
669
668
670
.. code-block:: python
669
671
670
-
classMyStreamBlockFactory(StreamBlockFactory):
672
+
classMyStreamBlockFactory(StreamBlockFactory):
671
673
classMeta:
672
674
model = MyStreamBlock # Auto-instantiated when needed
673
675
674
676
.. important::
675
677
**Why block definitions matter**
676
-
678
+
677
679
Wagtail block definitions are required to construct proper ``StreamValue`` objects. Without them, the system falls back to returning raw data structures. The options system ensures block definitions are available throughout the factory hierarchy by:
678
-
680
+
679
681
- Auto-instantiating models when needed
680
-
- Propagating definitions through ``SubFactory`` chains
682
+
- Propagating definitions through ``SubFactory`` chains
681
683
- Providing consistent access via ``get_block_definition()``
0 commit comments