mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-24 02:24:03 +03:00
Remove redundant test and move other to more appropriate place
This commit is contained in:
parent
25e01d0761
commit
d2da2f5e06
|
@ -542,15 +542,6 @@ class UniqueTogetherModel(models.Model):
|
|||
unique_together = ("foreign_key", "one_to_one")
|
||||
|
||||
|
||||
class NullableUniqueTogetherModel(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
field_1 = models.IntegerField(null=True)
|
||||
field_2 = models.TextField(null=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("field_1", "field_2")
|
||||
|
||||
|
||||
class TestRelationalFieldMappings(TestCase):
|
||||
def test_pk_relations(self):
|
||||
class TestSerializer(serializers.ModelSerializer):
|
||||
|
@ -740,17 +731,6 @@ class TestRelationalFieldMappings(TestCase):
|
|||
""")
|
||||
self.assertEqual(repr(TestSerializer()), expected)
|
||||
|
||||
def test_nullable_unique_together(self):
|
||||
class TestSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = NullableUniqueTogetherModel
|
||||
fields = ('name', 'field_1', 'field_2')
|
||||
|
||||
serializer = TestSerializer(data={"name": "Test"})
|
||||
self.assertTrue(serializer.is_valid(), serializer.errors)
|
||||
instance = serializer.save()
|
||||
assert isinstance(instance, NullableUniqueTogetherModel)
|
||||
|
||||
|
||||
class DisplayValueTargetModel(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
|
@ -1420,28 +1400,3 @@ class Issue6751Test(TestCase):
|
|||
serializer.save()
|
||||
|
||||
self.assertEqual(instance.char_field, 'value changed by signal')
|
||||
|
||||
|
||||
class UniqueConstraintNullableModel(models.Model):
|
||||
title = models.CharField(max_length=100)
|
||||
age = models.IntegerField(null=True)
|
||||
tag = models.CharField(max_length=100, null=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
# Unique constraint on 2 nullable fields
|
||||
models.UniqueConstraint(name='unique_constraint', fields=('age', 'tag'))
|
||||
]
|
||||
|
||||
|
||||
class TestUniqueConstraintWithNullableFields(TestCase):
|
||||
def test_nullable_unique_constraint_fields_are_not_required(self):
|
||||
class UniqueConstraintNullableSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = UniqueConstraintNullableModel
|
||||
fields = ('title', 'age', 'tag')
|
||||
|
||||
serializer = UniqueConstraintNullableSerializer(data={'title': 'Bob'})
|
||||
self.assertTrue(serializer.is_valid(), serializer.errors)
|
||||
result = serializer.save()
|
||||
self.assertIsInstance(result, UniqueConstraintNullableModel)
|
||||
|
|
|
@ -547,12 +547,30 @@ class UniqueConstraintModel(models.Model):
|
|||
]
|
||||
|
||||
|
||||
class UniqueConstraintNullableModel(models.Model):
|
||||
title = models.CharField(max_length=100)
|
||||
age = models.IntegerField(null=True)
|
||||
tag = models.CharField(max_length=100, null=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
# Unique constraint on 2 nullable fields
|
||||
models.UniqueConstraint(name='unique_constraint', fields=('age', 'tag'))
|
||||
]
|
||||
|
||||
|
||||
class UniqueConstraintSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = UniqueConstraintModel
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class UniqueConstraintNullableSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = UniqueConstraintNullableModel
|
||||
fields = ('title', 'age', 'tag')
|
||||
|
||||
|
||||
class TestUniqueConstraintValidation(TestCase):
|
||||
def setUp(self):
|
||||
self.instance = UniqueConstraintModel.objects.create(
|
||||
|
@ -619,6 +637,12 @@ class TestUniqueConstraintValidation(TestCase):
|
|||
ids_in_qs = {frozenset(v.queryset.values_list(flat=True)) for v in validators if hasattr(v, "queryset")}
|
||||
assert ids_in_qs == {frozenset([1]), frozenset([3])}
|
||||
|
||||
def test_nullable_unique_constraint_fields_are_not_required(self):
|
||||
serializer = UniqueConstraintNullableSerializer(data={'title': 'Bob'})
|
||||
self.assertTrue(serializer.is_valid(), serializer.errors)
|
||||
result = serializer.save()
|
||||
self.assertIsInstance(result, UniqueConstraintNullableModel)
|
||||
|
||||
|
||||
# Tests for `UniqueForDateValidator`
|
||||
# ----------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user