-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
quote_relation_name
support utility function
- Loading branch information
Showing
4 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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. | ||
""" | ||
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"' | ||
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"' | ||
|
||
|
||
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("my-db.my-schema.my-table") |