diff options
author | catherinedevlin <catherine.devlin@gmail.com> | 2018-05-20 19:35:09 -0400 |
---|---|---|
committer | Irina Truong <i.chernyavska@gmail.com> | 2018-06-16 21:47:18 -0700 |
commit | 74daa23a45e36264a9b8d5ab645682f088300973 (patch) | |
tree | 7b0883267746cde2c727789bb97ea17b95eeafc7 /tests | |
parent | bb8cbac3de146f7503d23e9994522a7a8b610b7b (diff) |
switched view query to imitating psql
Diffstat (limited to 'tests')
-rw-r--r-- | tests/parseutils/test_parseutils.py | 11 | ||||
-rw-r--r-- | tests/test_pgexecute.py | 37 | ||||
-rw-r--r-- | tests/utils.py | 1 |
3 files changed, 38 insertions, 11 deletions
diff --git a/tests/parseutils/test_parseutils.py b/tests/parseutils/test_parseutils.py index 28918c07..a1be2e4a 100644 --- a/tests/parseutils/test_parseutils.py +++ b/tests/parseutils/test_parseutils.py @@ -1,5 +1,5 @@ import pytest -from pgcli.packages.parseutils.tables import extract_tables, schema_table_split +from pgcli.packages.parseutils.tables import extract_tables from pgcli.packages.parseutils.utils import find_prev_keyword, is_open_quote @@ -265,12 +265,3 @@ def test_is_open_quote__closed(sql): ]) def test_is_open_quote__open(sql): assert is_open_quote(sql) - - -def test_schema_table_split(): - assert schema_table_split('myschema.mytable') == ('myschema', 'mytable') - assert schema_table_split('mytable') == ('%', 'mytable') - assert schema_table_split('') == ('%', '') - assert schema_table_split('myschema.mytable.foo') == ( - 'myschema', 'mytable.foo') - assert schema_table_split('%') == ('%', '%') diff --git a/tests/test_pgexecute.py b/tests/test_pgexecute.py index 56067906..3336d37e 100644 --- a/tests/test_pgexecute.py +++ b/tests/test_pgexecute.py @@ -360,3 +360,40 @@ def test_on_error_stop(executor, exception_formatter): # sql = "DO language plpgsql $$ BEGIN RAISE NOTICE '有人更改'; END $$;" # result = list(executor.run(sql)) # assert result[0][0] == u'NOTICE: 有人更改\n' + +@dbtest +def test_nonexistent_function_definition(executor): + with pytest.raises(RuntimeError): + result = executor.view_definition('there_is_no_such_function') + + +@dbtest +def test_function_definition(executor): + run(executor, ''' + CREATE OR REPLACE FUNCTION public.the_number_three() + RETURNS int + LANGUAGE sql + AS $function$ + select 3; + $function$ + ''') + result = executor.function_definition('the_number_three') + +@dbtest +def test_view_definition(executor): + run(executor, 'create table tbl1 (a text, b numeric)') + run(executor, 'create view vw1 AS SELECT * FROM tbl1') + run(executor, 'create materialized view mvw1 AS SELECT * FROM tbl1') + result = executor.view_definition('vw1') + assert 'FROM tbl1' in result + # import pytest; pytest.set_trace() + result = executor.view_definition('mvw1') + assert 'MATERIALIZED VIEW' in result + +@dbtest +def test_nonexistent_view_definition(executor): + with pytest.raises(RuntimeError): + result = executor.view_definition('there_is_no_such_view') + with pytest.raises(RuntimeError): + result = executor.view_definition('mvw1') + diff --git a/tests/utils.py b/tests/utils.py index 31fd12a3..53ce661b 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -15,7 +15,6 @@ def db_connection(dbname=None): conn.autocommit = True return conn - try: conn = db_connection() CAN_CONNECT_TO_DB = True |