mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +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
28
tests/model_fields/test_binaryfield.py
Normal file
28
tests/model_fields/test_binaryfield.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.test import TestCase
|
||||
from django.utils import six
|
||||
|
||||
from .models import DataModel
|
||||
|
||||
|
||||
class BinaryFieldTests(TestCase):
|
||||
binary_data = b'\x00\x46\xFE'
|
||||
|
||||
def test_set_and_retrieve(self):
|
||||
data_set = (self.binary_data, six.memoryview(self.binary_data))
|
||||
for bdata in data_set:
|
||||
dm = DataModel(data=bdata)
|
||||
dm.save()
|
||||
dm = DataModel.objects.get(pk=dm.pk)
|
||||
self.assertEqual(bytes(dm.data), bytes(bdata))
|
||||
# Resave (=update)
|
||||
dm.save()
|
||||
dm = DataModel.objects.get(pk=dm.pk)
|
||||
self.assertEqual(bytes(dm.data), bytes(bdata))
|
||||
# Test default value
|
||||
self.assertEqual(bytes(dm.short_data), b'\x08')
|
||||
|
||||
def test_max_length(self):
|
||||
dm = DataModel(short_data=self.binary_data * 4)
|
||||
with self.assertRaises(ValidationError):
|
||||
dm.full_clean()
|
Loading…
Add table
Add a link
Reference in a new issue