-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #813 from PetrDlouhy/explicit_bakery_indication
Raise exception when usage through model_mommy/model_bakery is not explicitly indicated
- Loading branch information
Showing
6 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ Topic docs: | |
utilities | ||
changelog | ||
technical_details | ||
testing | ||
|
||
.. toctree:: | ||
:maxdepth: 3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
=================== | ||
Testing MPTT models | ||
=================== | ||
|
||
|
||
Using testing generators | ||
======================== | ||
|
||
Using testing generators such as ``model_mommy`` or ``model_bakery`` is causing random tree fields values, which can cause unexpected behavior. | ||
To prevent that the ``django-mptt.MPTTModel`` will throw an Exception if made throught model_mommy/model_bakery in test environment unless | ||
the ``MPTT_ALLOW_TESTING_GENERATORS`` setting is set to True. | ||
|
||
You can set the ``MPTT_ALLOW_TESTING_GENERATORS`` setting to True in your Django testing settings.py file or by the ``@override_settings`` decorator for particular test. | ||
You would probably also have to use recipe and explicitly set the appropriate fields for the model. | ||
|
||
.. code-block:: python | ||
from django.test import override_settings | ||
from baker.recipe import Recipe | ||
@override_settings(MPTT_ALLOW_TESTING_GENERATORS=True) | ||
def test_mptt_allow_testing_generators(self): | ||
my_model_recipe = Recipe(MyMPTTModel, lft=None, rght=None) | ||
test_model_instance = my_model_recipe.make() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ mock-django | |
Django >= 2.2 | ||
coverage | ||
django-js-asset | ||
model-bakery | ||
model-mommy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters