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
54 lines (41 loc) · 1.74 KB
/
Copy pathtest_binary.py
File metadata and controls
54 lines (41 loc) · 1.74 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pytest
from tests import testmodels
from tortoise.exceptions import ConfigurationError, IntegrityError
from tortoise.fields import BinaryField
@pytest.mark.asyncio
async def test_empty(db):
with pytest.raises(IntegrityError):
await testmodels.BinaryFields.create()
@pytest.mark.asyncio
async def test_create(db):
obj0 = await testmodels.BinaryFields.create(binary=bytes(range(256)) * 500)
obj = await testmodels.BinaryFields.get(id=obj0.id)
assert obj.binary == bytes(range(256)) * 500
assert obj.binary_null is None
await obj.save()
obj2 = await testmodels.BinaryFields.get(id=obj.id)
assert obj == obj2
@pytest.mark.asyncio
async def test_values(db):
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")
assert values["binary"] == bytes(range(256))
assert values["binary_null"] == bytes(range(255, -1, -1))
@pytest.mark.asyncio
async def test_values_list(db):
obj0 = await testmodels.BinaryFields.create(binary=bytes(range(256)))
values = await testmodels.BinaryFields.get(id=obj0.id).values_list("binary", flat=True)
assert values == bytes(range(256))
def test_unique_fail():
with pytest.raises(ConfigurationError, match="can't be indexed"):
BinaryField(unique=True)
def test_index_fail():
with pytest.warns(
DeprecationWarning, match="`index` is deprecated, please use `db_index` instead"
):
with pytest.raises(ConfigurationError, match="can't be indexed"):
BinaryField(index=True)
with pytest.raises(ConfigurationError, match="can't be indexed"):
BinaryField(db_index=True)