File: testing.rst

package info (click to toggle)
python-django-mptt 0.18-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,180 kB
  • sloc: python: 5,135; javascript: 360; makefile: 132; sh: 12
file content (24 lines) | stat: -rw-r--r-- 1,034 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
===================
Testing MPTT models
===================


Using testing generators
========================

Using testing generators such as ``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 through 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()