diff --git a/tests/test_cli.py b/tests/test_cli.py index f08cf6b9f..422dc9d1b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -57,6 +57,19 @@ def patched_sys_stdin_read(): assert 'There was an error decoding the token' in str(excinfo.value) + def test_decode_payload_raises_terminal_not_a_tty(self, monkeypatch): + decode_args = ['--key', '1234', 'decode'] + parser = build_argparser() + args = parser.parse_args(decode_args) + + monkeypatch.setattr(sys.stdin, 'isatty', lambda: False) + monkeypatch.setattr(sys.stdin, 'read', lambda: 'token') + + with pytest.raises(IOError) as excinfo: + decode_payload(args) + assert 'Cannot read from stdin: terminal not a TTY' \ + in str(excinfo.value) + @pytest.mark.parametrize('key,name,job,exp,verify', [ ('1234', 'Vader', 'Sith', None, None), ('4567', 'Anakin', 'Jedi', '+1', None),