mirror of
https://github.com/scito/extract_otp_secret_keys
synced 2024-11-18 09:28:19 +00:00
mock no_args tests
This commit is contained in:
parent
9f0872c2d0
commit
95e7d73173
@ -2,3 +2,4 @@ wheel
|
|||||||
pytest
|
pytest
|
||||||
flake8
|
flake8
|
||||||
pylint
|
pylint
|
||||||
|
pytest-mock
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
cd /extract
|
cd /extract
|
||||||
pip install -U pytest && pytest "$@"
|
pip install -U pytest pytest-mock && pytest "$@"
|
||||||
|
@ -433,21 +433,37 @@ def test_extract_help(capsys):
|
|||||||
assert e.type == SystemExit
|
assert e.type == SystemExit
|
||||||
assert e.value.code == 0
|
assert e.value.code == 0
|
||||||
|
|
||||||
@pytest.mark.skipif(qreader_available, reason="Cannot test interactive mode")
|
def test_extract_no_arguments(capsys, mocker):
|
||||||
def test_extract_no_arguments(capsys):
|
if qreader_available:
|
||||||
# Act
|
# Arrange
|
||||||
with pytest.raises(SystemExit) as e:
|
otps = read_json('example_output.json')
|
||||||
extract_otp_secret_keys.main([])
|
mocker.patch('extract_otp_secret_keys.extract_otps_from_camera', return_value=otps)
|
||||||
|
|
||||||
# Assert
|
# Act
|
||||||
captured = capsys.readouterr()
|
extract_otp_secret_keys.main(['-c', '-'])
|
||||||
|
|
||||||
expected_err_msg = 'error: the following arguments are required: infile'
|
# Assert
|
||||||
|
captured = capsys.readouterr()
|
||||||
|
|
||||||
assert expected_err_msg in captured.err
|
expected_csv = read_csv('example_output.csv')
|
||||||
assert captured.out == ''
|
actual_csv = read_csv_str(captured.out)
|
||||||
assert e.value.code == 2
|
|
||||||
assert e.type == SystemExit
|
assert actual_csv == expected_csv
|
||||||
|
assert captured.err == ''
|
||||||
|
else:
|
||||||
|
# Act
|
||||||
|
with pytest.raises(SystemExit) as e:
|
||||||
|
extract_otp_secret_keys.main([])
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
captured = capsys.readouterr()
|
||||||
|
|
||||||
|
expected_err_msg = 'error: the following arguments are required: infile'
|
||||||
|
|
||||||
|
assert expected_err_msg in captured.err
|
||||||
|
assert captured.out == ''
|
||||||
|
assert e.value.code == 2
|
||||||
|
assert e.type == SystemExit
|
||||||
|
|
||||||
|
|
||||||
def test_verbose_and_quiet(capsys):
|
def test_verbose_and_quiet(capsys):
|
||||||
|
Loading…
Reference in New Issue
Block a user