Skip to content

Commit

Permalink
Added unit-tests for jazzband#615
Browse files Browse the repository at this point in the history
  • Loading branch information
bdabrowski committed Aug 20, 2024
1 parent 04fe33d commit 978f9c7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 4.2.15 on 2024-08-20 06:34

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('tests', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='BlueHeadDuck',
fields=[
('duck_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='tests.duck')),
],
options={
'abstract': False,
'base_manager_name': 'objects',
},
bases=('tests.duck',),
),
migrations.CreateModel(
name='PurpleHeadDuck',
fields=[
],
options={
'proxy': True,
'indexes': [],
'constraints': [],
},
bases=('tests.blueheadduck',),
),
]
25 changes: 25 additions & 0 deletions polymorphic/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,28 @@ class SubclassSelectorProxyConcreteModel(SubclassSelectorProxyModel):

class NonPolymorphicParent(PolymorphicModel, Group):
test = models.CharField(max_length=22, default="test_non_polymorphic_parent")


# models for https://github.com/jazzband/django-polymorphic/issues/615


class BlueHeadDuck(Duck):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# This wasn't run before the fix:
self.color = "blue"


class HomeDuck(models.Model):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.home = "Duckburg"

class Meta:
abstract = True


# Not sure if this will be necessary...
class PurpleHeadDuck(HomeDuck, BlueHeadDuck):
class Meta:
proxy = True
12 changes: 12 additions & 0 deletions polymorphic/tests/test_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from polymorphic.tests.models import Duck, PurpleHeadDuck


def test_transmogrify_with_init(db):
pur = PurpleHeadDuck.objects.create()
assert pur.color == "blue"
assert pur.home == "Duckburg"

pur = Duck.objects.get(id=pur.id)
assert pur.color == "blue"
# issues/615 fixes following line:
assert pur.home == "Duckburg"

0 comments on commit 978f9c7

Please sign in to comment.