diff options
| author | Simeon Simeonov | 2020-04-06 10:28:46 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2020-04-06 10:28:46 +0200 |
| commit | e297c0696cf594f8f700dd82fdcdda582e348eda (patch) | |
| tree | deea1cfef4041dc492a38d8304c20be14d18c8ba /tests/test_main.py | |
| parent | 097aaa49fa99cffec9db74432d7025457c34199e (diff) | |
Add a simple CLI interface with tests and update README.md
Diffstat (limited to 'tests/test_main.py')
| -rw-r--r-- | tests/test_main.py | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..b48f625 --- /dev/null +++ b/tests/test_main.py | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||
| 3 | # | ||
| 4 | # Copyright (c) 2020, Simeon Simeonov | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # Redistribution and use in source and binary forms, with or without | ||
| 8 | # modification, are permitted provided that the following conditions | ||
| 9 | # are met: | ||
| 10 | # 1. Redistributions of source code must retain the above copyright | ||
| 11 | # notice, this list of conditions and the following disclaimer. | ||
| 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| 13 | # this list of conditions and the following disclaimer in the documentation | ||
| 14 | # and/or other materials provided with the distribution. | ||
| 15 | # | ||
| 16 | # THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR | ||
| 17 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 18 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 19 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 20 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 21 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 25 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | """Tests for otp2289.__main__""" | ||
| 27 | import os | ||
| 28 | |||
| 29 | import pytest | ||
| 30 | |||
| 31 | from otp2289.__main__ import main | ||
| 32 | |||
| 33 | |||
| 34 | def test_main_generate_otp_response(capsys): | ||
| 35 | """tests main""" | ||
| 36 | args = ['--generate-otp-response', | ||
| 37 | '-a', | ||
| 38 | 'sha1', | ||
| 39 | '-i', | ||
| 40 | '99', | ||
| 41 | '-s', | ||
| 42 | 'TesT', | ||
| 43 | '-p', | ||
| 44 | 'This is a test.'] | ||
| 45 | with pytest.raises(SystemExit) as exit_info: | ||
| 46 | main(args) | ||
| 47 | captured = capsys.readouterr() | ||
| 48 | assert captured.out == (f'Seed: TesT, Step: 99, Hash: sha1{os.linesep}' | ||
| 49 | f'0x87fec7768b73ccf9{os.linesep}') | ||
| 50 | assert exit_info.type == SystemExit | ||
| 51 | assert exit_info.value.code == 0 | ||
| 52 | args.extend(['-f', 'token']) | ||
| 53 | with pytest.raises(SystemExit) as exit_info: | ||
| 54 | main(args) | ||
| 55 | captured = capsys.readouterr() | ||
| 56 | assert captured.out == (f'Seed: TesT, Step: 99, Hash: sha1{os.linesep}' | ||
| 57 | f'GAFF WAIT SKID GIG SKY EYED{os.linesep}') | ||
| 58 | assert exit_info.type == SystemExit | ||
| 59 | assert exit_info.value.code == 0 | ||
| 60 | args.append('-q') | ||
| 61 | with pytest.raises(SystemExit) as exit_info: | ||
| 62 | main(args) | ||
| 63 | captured = capsys.readouterr() | ||
| 64 | assert captured.out == f'GAFF WAIT SKID GIG SKY EYED{os.linesep}' | ||
| 65 | assert exit_info.type == SystemExit | ||
| 66 | assert exit_info.value.code == 0 | ||
| 67 | |||
| 68 | |||
| 69 | def test_main_generate_otp_range(capsys): | ||
| 70 | """tests main""" | ||
| 71 | args = ['--generate-otp-range', | ||
| 72 | '-i', | ||
| 73 | '2', | ||
| 74 | '-s', | ||
| 75 | 'TesT', | ||
| 76 | '-r', | ||
| 77 | '5', | ||
| 78 | '-p', | ||
| 79 | 'This is a test.'] | ||
| 80 | with pytest.raises(SystemExit) as exit_info: | ||
| 81 | main(args) | ||
| 82 | captured = capsys.readouterr() | ||
| 83 | assert captured.out == (f'Seed: TesT, Step: 2, Hash: md5, Range: 3' | ||
| 84 | f'{os.linesep}' | ||
| 85 | f'2: 0x4049f8b161669b7b{os.linesep}' | ||
| 86 | f'1: 0x7965e05436f5029f{os.linesep}' | ||
| 87 | f'0: 0x9e876134d90499dd{os.linesep}') | ||
| 88 | assert exit_info.type == SystemExit | ||
| 89 | assert exit_info.value.code == 0 | ||
| 90 | args.append('-q') | ||
| 91 | with pytest.raises(SystemExit) as exit_info: | ||
| 92 | main(args) | ||
| 93 | captured = capsys.readouterr() | ||
| 94 | assert captured.out == (f'2: 0x4049f8b161669b7b{os.linesep}' | ||
| 95 | f'1: 0x7965e05436f5029f{os.linesep}' | ||
| 96 | f'0: 0x9e876134d90499dd{os.linesep}') | ||
| 97 | assert exit_info.type == SystemExit | ||
| 98 | assert exit_info.value.code == 0 | ||
| 99 | args.extend(['-f', 'token']) | ||
| 100 | with pytest.raises(SystemExit) as exit_info: | ||
| 101 | main(args) | ||
| 102 | captured = capsys.readouterr() | ||
| 103 | assert captured.out == (f'2: THY AVON NO NECK COKE MOLL{os.linesep}' | ||
| 104 | f'1: EASE OIL FUM CURE AWRY AVIS{os.linesep}' | ||
| 105 | f'0: INCH SEA ANNE LONG AHEM TOUR{os.linesep}') | ||
| 106 | assert exit_info.type == SystemExit | ||
| 107 | assert exit_info.value.code == 0 | ||
| 108 | |||
| 109 | |||
| 110 | def test_main_initiate(capsys): | ||
| 111 | """tests main""" | ||
| 112 | args = ['--initiate-new-sequence', | ||
| 113 | '-i', | ||
| 114 | '500', | ||
| 115 | '-s', | ||
| 116 | 'TesT', | ||
| 117 | '-p', | ||
| 118 | 'This is a test.'] | ||
| 119 | with pytest.raises(SystemExit) as exit_info: | ||
| 120 | main(args) | ||
| 121 | captured = capsys.readouterr() | ||
| 122 | assert captured.out == (f'Seed: TesT, Step: 500, Hash: md5{os.linesep}' | ||
| 123 | f'0x2b8d82b6ac14346c{os.linesep}') | ||
| 124 | assert exit_info.type == SystemExit | ||
| 125 | assert exit_info.value.code == 0 | ||
| 126 | args.append('-q') | ||
| 127 | with pytest.raises(SystemExit) as exit_info: | ||
| 128 | main(args) | ||
| 129 | captured = capsys.readouterr() | ||
| 130 | assert captured.out == f'0x2b8d82b6ac14346c{os.linesep}' | ||
| 131 | assert exit_info.type == SystemExit | ||
| 132 | assert exit_info.value.code == 0 | ||
