mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from unittest import TestCase
|
|
|
|
from redash.query_runner.pg import build_schema
|
|
|
|
|
|
class TestBuildSchema(TestCase):
|
|
def test_handles_dups_between_public_and_other_schemas(self):
|
|
results = {
|
|
"rows": [
|
|
{
|
|
"table_schema": "public",
|
|
"table_name": "main.users",
|
|
"column_name": "id",
|
|
},
|
|
{"table_schema": "main", "table_name": "users", "column_name": "id"},
|
|
{"table_schema": "main", "table_name": "users", "column_name": "name"},
|
|
]
|
|
}
|
|
|
|
schema = {}
|
|
|
|
build_schema(results, schema)
|
|
|
|
self.assertIn("main.users", schema.keys())
|
|
self.assertListEqual(schema["main.users"]["columns"], ["id", "name"])
|
|
self.assertIn('public."main.users"', schema.keys())
|
|
self.assertListEqual(schema['public."main.users"']["columns"], ["id"])
|
|
|
|
def test_build_schema_with_data_types(self):
|
|
results = {
|
|
"rows": [
|
|
{"table_schema": "main", "table_name": "users", "column_name": "id", "data_type": "integer"},
|
|
{"table_schema": "main", "table_name": "users", "column_name": "name", "data_type": "varchar"},
|
|
]
|
|
}
|
|
|
|
schema = {}
|
|
|
|
build_schema(results, schema)
|
|
|
|
self.assertListEqual(
|
|
schema["main.users"]["columns"], [{"name": "id", "type": "integer"}, {"name": "name", "type": "varchar"}]
|
|
)
|