Refs #27804 -- Used subTest() in BinaryFieldTests.test_set_and_retrieve.

This commit is contained in:
Jon Dufresne 2019-06-06 21:04:56 -07:00 committed by Mariusz Felisiak
parent 8ba20d9071
commit 498092377b
1 changed files with 11 additions and 10 deletions

View File

@ -11,16 +11,17 @@ class BinaryFieldTests(TestCase):
def test_set_and_retrieve(self): def test_set_and_retrieve(self):
data_set = (self.binary_data, bytearray(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: for bdata in data_set:
dm = DataModel(data=bdata) with self.subTest(data=repr(bdata)):
dm.save() dm = DataModel(data=bdata)
dm = DataModel.objects.get(pk=dm.pk) dm.save()
self.assertEqual(bytes(dm.data), bytes(bdata)) dm = DataModel.objects.get(pk=dm.pk)
# Resave (=update) self.assertEqual(bytes(dm.data), bytes(bdata))
dm.save() # Resave (=update)
dm = DataModel.objects.get(pk=dm.pk) dm.save()
self.assertEqual(bytes(dm.data), bytes(bdata)) dm = DataModel.objects.get(pk=dm.pk)
# Test default value self.assertEqual(bytes(dm.data), bytes(bdata))
self.assertEqual(bytes(dm.short_data), b'\x08') # Test default value
self.assertEqual(bytes(dm.short_data), b'\x08')
def test_max_length(self): def test_max_length(self):
dm = DataModel(short_data=self.binary_data * 4) dm = DataModel(short_data=self.binary_data * 4)