Skip to content

Commit

Permalink
Add test to cover when terminal is not a TTY
Browse files Browse the repository at this point in the history
  • Loading branch information
jpadilla committed Nov 5, 2017
1 parent 6031675 commit 8d104bc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_cli.py
Expand Up @@ -57,6 +57,37 @@ def patched_sys_stdin_read():

assert 'There was an error decoding the token' in str(excinfo.value)

def test_decode_payload_terminal_tty(self, monkeypatch):
encode_args = [
'--key=secret-key',
'encode',
'name=hello-world',
]
parser = build_argparser()
parsed_encode_args = parser.parse_args(encode_args)
token = encode_payload(parsed_encode_args)

decode_args = ['--key=secret-key', 'decode']
parsed_decode_args = parser.parse_args(decode_args)

monkeypatch.setattr(sys.stdin, 'isatty', lambda: True)
monkeypatch.setattr(sys.stdin, 'readline', lambda: token)

actual = json.loads(decode_payload(parsed_decode_args))
assert actual['name'] == 'hello-world'

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)

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),
Expand Down

0 comments on commit 8d104bc

Please sign in to comment.