-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_support_util.py
More file actions
51 lines (39 loc) · 1.72 KB
/
test_support_util.py
File metadata and controls
51 lines (39 loc) · 1.72 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
import pytest
from sqlalchemy_cratedb.support import quote_relation_name
def test_quote_relation_name_once():
"""
Verify quoting a simple or full-qualified relation name.
"""
# Table name only.
assert quote_relation_name("my_table") == "my_table"
assert quote_relation_name("my-table") == '"my-table"'
assert quote_relation_name("MyTable") == '"MyTable"'
assert quote_relation_name('"MyTable"') == '"MyTable"'
# Schema and table name.
assert quote_relation_name("my_schema.my_table") == "my_schema.my_table"
assert quote_relation_name("my-schema.my_table") == '"my-schema".my_table'
assert quote_relation_name('"wrong-quoted-fqn.my_table"') == '"wrong-quoted-fqn.my_table"'
assert quote_relation_name('"my_schema"."my_table"') == '"my_schema"."my_table"'
# Catalog, schema, and table name.
assert quote_relation_name("crate.doc.t01") == "crate.doc.t01"
def test_quote_relation_name_twice():
"""
Verify quoting a relation name twice does not cause any harm.
"""
input_fqn = "foo-bar.baz_qux"
output_fqn = '"foo-bar".baz_qux'
assert quote_relation_name(input_fqn) == output_fqn
assert quote_relation_name(output_fqn) == output_fqn
def test_quote_relation_name_reserved_keywords():
"""
Verify quoting a simple relation name that is a reserved keyword.
"""
assert quote_relation_name("table") == '"table"'
assert quote_relation_name("true") == '"true"'
assert quote_relation_name("select") == '"select"'
def test_quote_relation_name_with_invalid_fqn():
"""
Verify quoting a relation name with an invalid fqn raises an error.
"""
with pytest.raises(ValueError):
quote_relation_name("too-many.my-db.my-schema.my-table")