forked from tortoise/tortoise-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_update.py
More file actions
76 lines (59 loc) · 2.5 KB
/
test_update.py
File metadata and controls
76 lines (59 loc) · 2.5 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import asyncio
import random
from tests.testmodels import BenchmarkFewFields, BenchmarkManyFields
def test_update_few_fields_with_save(benchmark, few_fields_benchmark_dataset):
loop = asyncio.get_event_loop()
@benchmark
def bench():
async def _bench():
instance = random.choice(few_fields_benchmark_dataset) # nosec
instance.level = random.randint(0, 100) # nosec
instance.text = "updated " + str(random.randint(0, 100)) # nosec
await instance.save()
loop.run_until_complete(_bench())
def test_update_many_fields_with_save(
benchmark, many_fields_benchmark_dataset, gen_many_fields_data
):
loop = asyncio.get_event_loop()
@benchmark
def bench():
async def _bench():
instance = random.choice(many_fields_benchmark_dataset) # nosec
rand_val = random.randint(0, 100) # nosec
instance.col_float1 = random.uniform(0, 100) # nosec
instance.col_smallint1 = rand_val
instance.col_int1 = rand_val
instance.col_bigint1 = rand_val
instance.col_char1 = "updated " + str(rand_val)
instance.col_text1 = "updated " + str(rand_val)
await instance.save()
loop.run_until_complete(_bench())
def test_update_few_fields_with_update(benchmark, few_fields_benchmark_dataset):
loop = asyncio.get_event_loop()
@benchmark
def bench():
async def _bench():
instance = random.choice(few_fields_benchmark_dataset) # nosec
await BenchmarkFewFields.filter(id=instance.id).update(
level=random.randint(0, 100), # nosec
text="updated " + str(random.randint(0, 100)), # nosec
)
loop.run_until_complete(_bench())
def test_update_many_fields_with_update(
benchmark, many_fields_benchmark_dataset, gen_many_fields_data
):
loop = asyncio.get_event_loop()
@benchmark
def bench():
async def _bench():
instance = random.choice(many_fields_benchmark_dataset) # nosec
rand_val = random.randint(0, 100) # nosec
await BenchmarkManyFields.filter(id=instance.id).update(
col_float1=random.uniform(0, 100), # nosec
col_smallint1=rand_val,
col_int1=rand_val,
col_bigint1=rand_val,
col_char1="updated " + str(rand_val),
col_text1="updated " + str(rand_val),
)
loop.run_until_complete(_bench())