Skip to content

Commit 2480312

Browse files
committed
add tests
1 parent e7104d3 commit 2480312

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed

tests/aio/test_table_client.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import pytest
2+
import ydb
3+
4+
5+
class TestTableClient:
6+
@pytest.mark.asyncio
7+
async def test_create_table(self, driver: ydb.aio.Driver):
8+
client = driver.table_client
9+
table_name = "/local/testtableclient"
10+
try:
11+
await client.drop_table(table_name)
12+
except ydb.SchemeError:
13+
pass
14+
15+
with pytest.raises(ydb.SchemeError):
16+
await client.describe_table(table_name)
17+
18+
description = (
19+
ydb.TableDescription()
20+
.with_primary_keys("key1", "key2")
21+
.with_columns(
22+
ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
23+
ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
24+
ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)),
25+
)
26+
)
27+
28+
await client.create_table(table_name, description)
29+
30+
actual_description = await client.describe_table(table_name)
31+
32+
assert actual_description.columns == description.columns
33+
34+
@pytest.mark.asyncio
35+
async def test_alter_table(self, driver: ydb.aio.Driver):
36+
client = driver.table_client
37+
38+
table_name = "/local/testtableclient"
39+
try:
40+
await client.drop_table(table_name)
41+
except ydb.SchemeError:
42+
pass
43+
44+
description = (
45+
ydb.TableDescription()
46+
.with_primary_keys("key1", "key2")
47+
.with_columns(
48+
ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
49+
ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
50+
ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)),
51+
)
52+
)
53+
54+
await client.create_table(table_name, description)
55+
56+
await client.alter_table(table_name, add_columns=[
57+
ydb.Column("value2", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
58+
])
59+
60+
description = await client.describe_table(table_name)
61+
assert len(description.columns) == 4
62+
63+
@pytest.mark.asyncio
64+
async def test_copy_table(self, driver: ydb.aio.Driver):
65+
client = driver.table_client
66+
table_name = "/local/testtableclient"
67+
try:
68+
await client.drop_table(table_name)
69+
except ydb.SchemeError:
70+
pass
71+
72+
description = (
73+
ydb.TableDescription()
74+
.with_primary_keys("key1", "key2")
75+
.with_columns(
76+
ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
77+
ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
78+
ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)),
79+
)
80+
)
81+
82+
await client.create_table(table_name, description)
83+
84+
await client.copy_table(table_name, table_name + "_copy")
85+
86+
copied_description = await client.describe_table(table_name + "_copy")
87+
88+
assert description.columns == copied_description.columns

tests/table/test_table_client.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import pytest
2+
import ydb
3+
4+
5+
class TestTableClient:
6+
def test_create_table(self, driver_sync: ydb.Driver):
7+
client = driver_sync.table_client
8+
table_name = "/local/testtableclient"
9+
try:
10+
client.drop_table(table_name)
11+
except ydb.SchemeError:
12+
pass
13+
14+
with pytest.raises(ydb.SchemeError):
15+
client.describe_table(table_name)
16+
17+
description = (
18+
ydb.TableDescription()
19+
.with_primary_keys("key1", "key2")
20+
.with_columns(
21+
ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
22+
ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
23+
ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)),
24+
)
25+
)
26+
27+
client.create_table(table_name, description)
28+
29+
actual_description = client.describe_table(table_name)
30+
31+
assert actual_description.columns == description.columns
32+
33+
def test_alter_table(self, driver_sync: ydb.Driver):
34+
client = driver_sync.table_client
35+
36+
table_name = "/local/testtableclient"
37+
try:
38+
client.drop_table(table_name)
39+
except ydb.SchemeError:
40+
pass
41+
42+
description = (
43+
ydb.TableDescription()
44+
.with_primary_keys("key1", "key2")
45+
.with_columns(
46+
ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
47+
ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
48+
ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)),
49+
)
50+
)
51+
52+
client.create_table(table_name, description)
53+
54+
client.alter_table(table_name, add_columns=[
55+
ydb.Column("value2", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
56+
])
57+
58+
description = client.describe_table(table_name)
59+
assert len(description.columns) == 4
60+
61+
def test_copy_table(self, driver_sync: ydb.Driver):
62+
client = driver_sync.table_client
63+
table_name = "/local/testtableclient"
64+
try:
65+
client.drop_table(table_name)
66+
except ydb.SchemeError:
67+
pass
68+
69+
description = (
70+
ydb.TableDescription()
71+
.with_primary_keys("key1", "key2")
72+
.with_columns(
73+
ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
74+
ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
75+
ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)),
76+
)
77+
)
78+
79+
client.create_table(table_name, description)
80+
81+
client.copy_table(table_name, table_name + "_copy")
82+
83+
copied_description = client.describe_table(table_name + "_copy")
84+
85+
assert description.columns == copied_description.columns

0 commit comments

Comments
 (0)