Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Add an explicit name to the models.
Otherwise we'll get a conflict between tests.test_model_serializer.ParentModel and tests.test_multitable_inheritance.ParentModel.
  • Loading branch information
xordoquy committed Jan 21, 2016
commit e670284f07302631de52c0ce5bc379d087d8ea71
18 changes: 9 additions & 9 deletions tests/test_model_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ class ChoicesModel(models.Model):
choices_field_with_nonstandard_args = models.DecimalField(max_digits=3, decimal_places=1, choices=DECIMAL_CHOICES, verbose_name='A label')


class ParentModel(models.Model):
class Issue3674ParentModel(models.Model):
title = models.CharField(max_length=64)


class ChildModel(models.Model):
parent = models.ForeignKey(ParentModel, related_name='children')
class Issue3674ChildModel(models.Model):
parent = models.ForeignKey(Issue3674ParentModel, related_name='children')
value = models.CharField(primary_key=True, max_length=64)


Expand Down Expand Up @@ -989,22 +989,22 @@ def test_nonID_PK_foreignkey_model_serializer(self):

class TestChildModelSerializer(serializers.ModelSerializer):
class Meta:
model = ChildModel
model = Issue3674ChildModel
fields = ('value', 'parent')

class TestParentModelSerializer(serializers.ModelSerializer):
class Meta:
model = ParentModel
model = Issue3674ParentModel
fields = ('id', 'title', 'children')

parent = ParentModel.objects.create(title='abc')
child = ChildModel.objects.create(value='def', parent=parent)
parent = Issue3674ParentModel.objects.create(title='abc')
child = Issue3674ChildModel.objects.create(value='def', parent=parent)

parent_serializer = TestParentModelSerializer(parent)
child_serializer = TestChildModelSerializer(child)

parent_expected = {u'children': [u'def'], u'id': 1, u'title': u'abc'}
parent_expected = {'children': ['def'], 'id': 1, 'title': 'abc'}
self.assertEqual(parent_serializer.data, parent_expected)

child_expected = {u'parent': 1, u'value': u'def'}
child_expected = {'parent': 1, 'value': 'def'}
self.assertEqual(child_serializer.data, child_expected)