Added tests for using bytearray with BinaryField and corrected docs.
This commit is contained in:
parent
e9defb3f6e
commit
b3b47bf515
|
@ -416,8 +416,8 @@ guaranteed to fit numbers from ``-9223372036854775808`` to
|
|||
|
||||
.. class:: BinaryField(max_length=None, **options)
|
||||
|
||||
A field to store raw binary data. It can be assigned :class:`bytes` or a
|
||||
:class:`memoryview`.
|
||||
A field to store raw binary data. It can be assigned :class:`bytes`,
|
||||
:class:`bytearray`, or :class:`memoryview`.
|
||||
|
||||
By default, ``BinaryField`` sets :attr:`~Field.editable` to ``False``, in which
|
||||
case it can't be included in a :class:`~django.forms.ModelForm`.
|
||||
|
|
|
@ -9,7 +9,7 @@ class BinaryFieldTests(TestCase):
|
|||
binary_data = b'\x00\x46\xFE'
|
||||
|
||||
def test_set_and_retrieve(self):
|
||||
data_set = (self.binary_data, memoryview(self.binary_data))
|
||||
data_set = (self.binary_data, bytearray(self.binary_data), memoryview(self.binary_data))
|
||||
for bdata in data_set:
|
||||
dm = DataModel(data=bdata)
|
||||
dm.save()
|
||||
|
@ -40,6 +40,11 @@ class BinaryFieldTests(TestCase):
|
|||
DataModel.objects.create(data=b'\xef\xbb\xbf')
|
||||
self.assertSequenceEqual(DataModel.objects.filter(data=self.binary_data), [dm])
|
||||
|
||||
def test_filter_bytearray(self):
|
||||
dm = DataModel.objects.create(data=self.binary_data)
|
||||
DataModel.objects.create(data=b'\xef\xbb\xbf')
|
||||
self.assertSequenceEqual(DataModel.objects.filter(data=bytearray(self.binary_data)), [dm])
|
||||
|
||||
def test_filter_memoryview(self):
|
||||
dm = DataModel.objects.create(data=self.binary_data)
|
||||
DataModel.objects.create(data=b'\xef\xbb\xbf')
|
||||
|
|
Loading…
Reference in New Issue