Skip to content

Commit 37c0486

Browse files
committed
add REPL sandbox mode test coverage
1 parent e6cbfc6 commit 37c0486

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/pytests/test_main_modes_repl.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,26 @@ def run(self, text: str) -> Iterator[SQLResult]:
937937
assert any('reconnection failed' in msg for msg in cli.echo_calls)
938938

939939

940+
def test_one_iteration_enters_sandbox_mode_on_must_change_password_error(monkeypatch: pytest.MonkeyPatch) -> None:
941+
patch_repl_runtime_defaults(monkeypatch)
942+
943+
class FakeSQLExecute:
944+
dbname = 'db'
945+
connection_id = 0
946+
947+
def run(self, text: str) -> Iterator[SQLResult]:
948+
raise pymysql.OperationalError(repl_mode.ER_MUST_CHANGE_PASSWORD, 'must change password')
949+
950+
cli = make_repl_cli(FakeSQLExecute())
951+
952+
repl_mode._one_iteration(cli, repl_mode.ReplState(), 'SELECT 1')
953+
954+
assert cli.sandbox_mode is True
955+
assert any('ERROR 1820' in msg for msg in cli.echo_calls)
956+
assert cli.query_history[-1].query == 'SELECT 1'
957+
assert cli.query_history[-1].successful is False
958+
959+
940960
def test_one_iteration_covers_redirect_destructive_success_refresh_and_logfile(monkeypatch: pytest.MonkeyPatch) -> None:
941961
patch_repl_runtime_defaults(monkeypatch)
942962

0 commit comments

Comments
 (0)