forked from tortoise/tortoise-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_binary.py
More file actions
40 lines (33 loc) · 1.67 KB
/
test_binary.py
File metadata and controls
40 lines (33 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from tests import testmodels
from tortoise.contrib import test
from tortoise.exceptions import ConfigurationError, IntegrityError
from tortoise.fields import BinaryField
class TestBinaryFields(test.TestCase):
async def test_empty(self):
with self.assertRaises(IntegrityError):
await testmodels.BinaryFields.create()
async def test_create(self):
obj0 = await testmodels.BinaryFields.create(binary=bytes(range(256)) * 500)
obj = await testmodels.BinaryFields.get(id=obj0.id)
self.assertEqual(obj.binary, bytes(range(256)) * 500)
self.assertEqual(obj.binary_null, None)
await obj.save()
obj2 = await testmodels.BinaryFields.get(id=obj.id)
self.assertEqual(obj, obj2)
async def test_values(self):
obj0 = await testmodels.BinaryFields.create(
binary=bytes(range(256)), binary_null=bytes(range(255, -1, -1))
)
values = await testmodels.BinaryFields.get(id=obj0.id).values("binary", "binary_null")
self.assertEqual(values["binary"], bytes(range(256)))
self.assertEqual(values["binary_null"], bytes(range(255, -1, -1)))
async def test_values_list(self):
obj0 = await testmodels.BinaryFields.create(binary=bytes(range(256)))
values = await testmodels.BinaryFields.get(id=obj0.id).values_list("binary", flat=True)
self.assertEqual(values, bytes(range(256)))
def test_unique_fail(self):
with self.assertRaisesRegex(ConfigurationError, "can't be indexed"):
BinaryField(unique=True)
def test_index_fail(self):
with self.assertRaisesRegex(ConfigurationError, "can't be indexed"):
BinaryField(index=True)