Skip to content

Commit

Permalink
Add a test to check that we can't ask for m2m dirty fields if we have…
Browse files Browse the repository at this point in the history
… not enabled the m2m check mode
  • Loading branch information
romgar committed Jul 23, 2016
1 parent 143d67b commit c8a320f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/models.py
Expand Up @@ -91,3 +91,8 @@ def pre_save(instance, *args, **kwargs):
instance.data_updated_on_presave = 'presave_value'

pre_save.connect(TestModelWithPreSaveSignal.pre_save, sender=TestModelWithPreSaveSignal)


class TestModelWithoutM2MCheck(DirtyFieldsMixin, models.Model):
characters = models.CharField(blank=True, max_length=80)
ENABLE_M2M_CHECK = False
11 changes: 10 additions & 1 deletion tests/test_m2m_fields.py
@@ -1,6 +1,7 @@
import pytest

from .models import TestModel, TestM2MModel, TestModelWithCustomPK, TestM2MModelWithCustomPKOnM2M
from .models import TestModel, TestM2MModel, TestModelWithCustomPK, TestM2MModelWithCustomPKOnM2M, \
TestModelWithoutM2MCheck


@pytest.mark.django_db
Expand Down Expand Up @@ -32,3 +33,11 @@ def test_m2m_check_with_custom_primary_key():
# This line was triggering this error:
# AttributeError: 'TestModelWithCustomPK' object has no attribute 'id'
m2m_model.m2m_field.add(tm)


@pytest.mark.django_db
def test_m2m_disabled_does_not_allow_to_check_m2m_fields():
tm = TestModelWithoutM2MCheck.objects.create()

with pytest.raises(Exception):
assert tm.get_dirty_fields(check_m2m={'dummy': True})

0 comments on commit c8a320f

Please sign in to comment.