1import sys
2import pytest
3import psycopg2.extras
4from pytest_postgresql import factories
5from pathlib import Path
6import sh
7from sh import psql
8
9
10@pytest.fixture
11def python():
12 return sh.Command(sys.executable)
13
14
15@pytest.fixture
16def ddl_tool(python, project_root):
17 return python.bake(
18 project_root / "bin/chartepssg",
19 "ddl",
20 "--db=integrationtest",
21 _truncate_exc=False,
22 )
23
24
25def test_ddl_tool(ddl_tool, psql_conn):
26 cursor = psql_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
27 cursor.execute(
28 "select a.table_name from information_schema.tables a where a.table_schema = 'public' and a.table_type = 'BASE TABLE' order by a.table_name;"
29 )
30 ret = [x[0] for x in cursor.fetchall()]
31 assert [] == ret
32
33 ddl_tool("--all-ts", "--execute")
34 ddl_tool("--all-sys", "--execute")
35 ddl_tool("--all-cal", "--execute")
36 ddl_tool("--all-functions", "--execute")
37 cursor.execute(
38 "select a.table_name from information_schema.tables a where a.table_schema = 'public' and a.table_type = 'BASE TABLE' order by a.table_name;"
39 )
40 ret = list(sorted(x[0] for x in cursor.fetchall()))
41 from pprint import pprint
42
43 pprint(ret)
44 expected = list(
45 sorted(
46 [
47 "ev_store",
48 "events",
49 "orbit4ant",
50 "predicted_orbit",
51 "tc_ack_store",
52 "tc_store",
53 "tm",
54 "tm_stats",
55 ]
56 )
57 )
58 set_expec = set(expected)
59 set_actual = set(ret)
60 assert set_expec.issubset(set_actual)