Skip to content

Commit 6b51632

Browse files
author
Charles Allatson
committed
Add test for polymorphic bugfix
1 parent d0e3c46 commit 6b51632

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.2 on 2019-06-07 06:46
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('example', '0006_auto_20181228_0752'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='artproject',
15+
name='description',
16+
field=models.CharField(max_length=100, null=True),
17+
),
18+
]

example/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class Project(PolymorphicModel):
153153

154154
class ArtProject(Project):
155155
artist = models.CharField(max_length=30)
156+
description = models.CharField(max_length=100, null=True)
156157

157158

158159
class ResearchProject(Project):

example/tests/integration/test_polymorphism.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ def test_polymorphism_on_polymorphic_model_detail_patch(single_art_project, clie
5959
assert new_content['data']['attributes']['artist'] == test_artist
6060

6161

62+
def test_patch_on_polymorphic_model_without_including_required_field(single_art_project, client):
63+
url = reverse("project-detail", kwargs={'pk': single_art_project.pk})
64+
data = {
65+
'data': {
66+
'id': single_art_project.pk,
67+
'type': 'artProjects',
68+
'attributes': {
69+
'description': 'New description'
70+
}
71+
}
72+
}
73+
response = client.patch(url, data)
74+
assert response.json()['data']['attributes']['description'] == 'New description'
75+
76+
6277
def test_polymorphism_on_polymorphic_model_list_post(client):
6378
test_topic = 'New test topic {}'.format(random.randint(0, 999999))
6479
test_artist = 'test-{}'.format(random.randint(0, 999999))

0 commit comments

Comments
 (0)