Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mailing/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for mailing app forms."""
from django.test import TestCase
from django.contrib.contenttypes.models import ContentType

from mailing.tests.forms import TestBaseEmailTemplateForm

Expand All @@ -13,6 +14,10 @@ def setUp(self):
"internal_name": "notification 01",
}

def tearDown(self):
super().tearDown()
ContentType.objects.clear_cache()

def test_validate_required_fields(self):
required = set(self.data)
form = TestBaseEmailTemplateForm(data={})
Expand Down
2 changes: 2 additions & 0 deletions pydotorg/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@
REST_FRAMEWORK['DEFAULT_RENDERER_CLASSES'] += (
'rest_framework.renderers.BrowsableAPIRenderer',
)

BAKER_CUSTOM_CLASS = "pydotorg.tests.baker.PolymorphicAwareBaker"
17 changes: 17 additions & 0 deletions pydotorg/tests/baker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from polymorphic.models import PolymorphicModel
from model_bakery import baker


class PolymorphicAwareBaker(baker.Baker):
"""
Our custom model baker ignores the polymorphic_ctype field on all polymorphic
models - this allows the base class to set it correctly.

See https://github.com/python/pythondotorg/issues/2567
"""

def get_fields(self):
fields = super().get_fields()
if issubclass(self.model, PolymorphicModel):
fields = {field for field in fields if field.name != "polymorphic_ctype"}
return fields