mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-24 10:34:03 +03:00
Simplify test case
This commit is contained in:
parent
d33bf12a91
commit
2e0b394bbe
|
@ -1329,34 +1329,24 @@ class Issue6751Test(TestCase):
|
||||||
self.assertEqual(instance.char_field, 'value changed by signal')
|
self.assertEqual(instance.char_field, 'value changed by signal')
|
||||||
|
|
||||||
|
|
||||||
class Issue7489Parent(models.Model):
|
class Issue7489Model(models.Model):
|
||||||
pass
|
field1 = models.CharField(max_length=1, default='A')
|
||||||
|
field2 = models.CharField(max_length=1, default='A')
|
||||||
|
field3 = models.CharField(max_length=1, default='A')
|
||||||
class Issue7489Child(models.Model):
|
|
||||||
parent = models.ForeignKey(Issue7489Parent, on_delete=models.CASCADE)
|
|
||||||
stage = models.CharField(max_length=1, choices=(('A', 'A'), ('B', 'B')), default='A')
|
|
||||||
is_thing = models.BooleanField(default=False)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ('parent', 'stage')
|
unique_together = ('field1', 'field2')
|
||||||
|
|
||||||
|
|
||||||
class Issue7489ChildSerializer(serializers.ModelSerializer):
|
class Issue7489Serializer(serializers.ModelSerializer):
|
||||||
parent = serializers.PrimaryKeyRelatedField(
|
|
||||||
allow_null=True,
|
|
||||||
queryset=Issue7489Parent.objects.all(),
|
|
||||||
required=False)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Issue7489Child
|
model = Issue7489Model
|
||||||
fields = ('parent', 'stage')
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
class IssueTest(TestCase):
|
class Issue7489Test(TestCase):
|
||||||
def test_model_serializer_inserts_choices_default_on_unique_together_validation(self):
|
def test_model_serializer_inserts_choices_default_on_unique_together_validation(self):
|
||||||
parent = Issue7489Parent.objects.create()
|
Issue7489Model.objects.create(field1='A', field2='A')
|
||||||
Issue7489Child.objects.create(parent=parent, stage='A')
|
b = Issue7489Model.objects.create(field1='A', field2='B')
|
||||||
child_b = Issue7489Child.objects.create(parent=parent, stage='B')
|
serializer = Issue7489Serializer(instance=b, data={'field3': 'X'})
|
||||||
serializer = Issue7489ChildSerializer(instance=child_b, data={'is_thing': True})
|
|
||||||
self.assertTrue(serializer.is_valid(), serializer.errors)
|
self.assertTrue(serializer.is_valid(), serializer.errors)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user