-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathtest_executemany.py
107 lines (84 loc) · 3.35 KB
/
test_executemany.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import pytest
from gino import MultipleResultsFound, NoResultFound
from .models import db, User
pytestmark = pytest.mark.asyncio
# noinspection PyUnusedLocal
async def test_status(bind):
statement, params = db.compile(
User.insert(), [dict(name="1"), dict(name="2")])
assert statement == (
"INSERT INTO gino_users (name, props, type) " "VALUES (%s, %s, %s)")
assert params == (("1", '"{}"', "USER"), ("2", '"{}"', "USER"))
result = await User.insert().gino.status(dict(name="1"), dict(name="2"))
assert result is None
assert len(await User.query.gino.all()) == 2
# noinspection PyUnusedLocal
async def test_all(bind):
result = await User.insert().gino.all(dict(name="1"), dict(name="2"))
assert result is None
rows = await User.query.gino.all()
assert len(rows) == 2
assert set(u.nickname for u in rows) == {"1", "2"}
result = await User.insert().gino.all(dict(name="3"), dict(name="4"))
assert result is None
rows = await User.query.gino.all()
assert len(rows) == 4
assert set(u.nickname for u in rows) == {"1", "2", "3", "4"}
# noinspection PyUnusedLocal
async def test_first(bind):
result = await User.insert().gino.first(dict(name="1"), dict(name="2"))
assert result is None
rows = await User.query.gino.all()
assert len(await User.query.gino.all()) == 2
assert set(u.nickname for u in rows) == {"1", "2"}
result = await User.insert().gino.first(dict(name="3"), dict(name="4"))
assert result is None
rows = await User.query.gino.all()
assert len(rows) == 4
assert set(u.nickname for u in rows) == {"1", "2", "3", "4"}
# noinspection PyUnusedLocal
async def test_one_or_none(bind):
row = await User.query.gino.one_or_none()
assert row is None
await User.create(nickname="0")
row = await User.query.gino.one_or_none()
assert row.nickname == "0"
result = (
await User.insert()
.gino.one_or_none(dict(name="1"), dict(name="2"))
)
assert result is None
rows = await User.query.gino.all()
assert len(await User.query.gino.all()) == 3
assert set(u.nickname for u in rows) == {"0", "1", "2"}
with pytest.raises(MultipleResultsFound):
row = await User.query.gino.one_or_none()
# noinspection PyUnusedLocal
async def test_one(bind):
with pytest.raises(NoResultFound):
row = await User.query.gino.one()
await User.create(nickname="0")
row = await User.query.gino.one()
assert row.nickname == "0"
with pytest.raises(NoResultFound):
await User.insert().gino.one(dict(name="1"), dict(name="2"))
rows = await User.query.gino.all()
assert len(await User.query.gino.all()) == 3
assert set(u.nickname for u in rows) == {"0", "1", "2"}
with pytest.raises(MultipleResultsFound):
row = await User.query.gino.one()
# noinspection PyUnusedLocal
async def test_scalar(bind):
result = (
await User.insert()
.gino.scalar(dict(name="1"), dict(name="2"))
)
assert result is None
rows = await User.query.gino.all()
assert len(await User.query.gino.all()) == 2
assert set(u.nickname for u in rows) == {"1", "2"}
result = await User.insert().gino.scalar(dict(name="3"), dict(name="4"))
assert result is None
rows = await User.query.gino.all()
assert len(rows) == 4
assert set(u.nickname for u in rows) == {"1", "2", "3", "4"}