2016-06-02 22:37:03 +03:00
|
|
|
from pgcli.main import PGCli
|
|
|
|
from mock import Mock
|
|
|
|
|
|
|
|
DEFAULT = PGCli().row_limit
|
|
|
|
LIMIT = DEFAULT + 1000
|
|
|
|
|
|
|
|
|
|
|
|
over_default = Mock()
|
2016-06-03 01:08:51 +03:00
|
|
|
over_default.configure_mock(rowcount=DEFAULT + 10)
|
2016-06-02 22:37:03 +03:00
|
|
|
|
|
|
|
over_limit = Mock()
|
2016-06-03 01:08:51 +03:00
|
|
|
over_limit.configure_mock(rowcount=LIMIT + 10)
|
2016-06-02 22:37:03 +03:00
|
|
|
|
|
|
|
low_count = Mock()
|
2016-06-03 01:08:51 +03:00
|
|
|
low_count.configure_mock(rowcount=1)
|
2016-06-02 22:37:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_default_row_limit():
|
|
|
|
cli = PGCli()
|
|
|
|
stmt = "SELECT * FROM students"
|
|
|
|
result = cli._should_show_limit_prompt(stmt, low_count)
|
|
|
|
assert result is False
|
|
|
|
|
|
|
|
result = cli._should_show_limit_prompt(stmt, over_default)
|
|
|
|
assert result is True
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_row_limit():
|
|
|
|
cli = PGCli(row_limit=LIMIT)
|
|
|
|
stmt = "SELECT * FROM students"
|
|
|
|
result = cli._should_show_limit_prompt(stmt, over_default)
|
|
|
|
assert result is False
|
|
|
|
|
|
|
|
result = cli._should_show_limit_prompt(stmt, over_limit)
|
|
|
|
assert result is True
|
|
|
|
|
|
|
|
|
|
|
|
def test_no_limit():
|
|
|
|
cli = PGCli(row_limit=0)
|
|
|
|
stmt = "SELECT * FROM students"
|
|
|
|
|
|
|
|
result = cli._should_show_limit_prompt(stmt, over_limit)
|
|
|
|
assert result is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_row_limit_on_non_select():
|
|
|
|
cli = PGCli()
|
|
|
|
stmt = "UPDATE students set name='Boby'"
|
|
|
|
result = cli._should_show_limit_prompt(stmt, None)
|
|
|
|
assert result is False
|
|
|
|
|
|
|
|
cli = PGCli(row_limit=0)
|
|
|
|
result = cli._should_show_limit_prompt(stmt, over_default)
|
|
|
|
assert result is False
|