mirror of
https://github.com/django/django.git
synced 2025-08-30 23:37:50 +00:00
Split model_fields tests into different files.
This commit is contained in:
parent
14e6823d09
commit
3c1b572f18
17 changed files with 1023 additions and 1055 deletions
34
tests/model_fields/test_floatfield.py
Normal file
34
tests/model_fields/test_floatfield.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
from django.db import transaction
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import FloatModel
|
||||
|
||||
|
||||
class TestFloatField(TestCase):
|
||||
|
||||
def test_float_validates_object(self):
|
||||
instance = FloatModel(size=2.5)
|
||||
# Try setting float field to unsaved object
|
||||
instance.size = instance
|
||||
with transaction.atomic():
|
||||
with self.assertRaises(TypeError):
|
||||
instance.save()
|
||||
# Set value to valid and save
|
||||
instance.size = 2.5
|
||||
instance.save()
|
||||
self.assertTrue(instance.id)
|
||||
# Set field to object on saved instance
|
||||
instance.size = instance
|
||||
msg = (
|
||||
'Tried to update field model_fields.FloatModel.size with a model '
|
||||
'instance, <FloatModel: FloatModel object>. Use a value '
|
||||
'compatible with FloatField.'
|
||||
)
|
||||
with transaction.atomic():
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
instance.save()
|
||||
# Try setting field to object on retrieved object
|
||||
obj = FloatModel.objects.get(pk=instance.id)
|
||||
obj.size = obj
|
||||
with self.assertRaises(TypeError):
|
||||
obj.save()
|
Loading…
Add table
Add a link
Reference in a new issue