aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/mass-pnf-sim/test_cli.py
blob: f574a725da5b852eb7128da04641f45f4beeac6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pytest
from MassPnfSim import MassPnfSim
from test_settings import SIM_INSTANCES

@pytest.mark.parametrize(('expect_string, cli_opts'), [
    ("bootstrap: error: the following arguments are required: --urlves, --ipfileserver, --typefileserver, --ipstart",
     ['bootstrap']),
    ("bootstrap: error: argument --typefileserver: invalid choice: 'dummy' (choose from 'sftp', 'ftps')",
     ['bootstrap', '--typefileserver', 'dummy']),
    ("bootstrap: error: argument --urlves: invalid_url is not a valid URL",
     ['bootstrap', '--urlves', 'invalid_url']),
    ("bootstrap: error: argument --ipstart: x.x.x.x is not a valid IP address",
     ['bootstrap', '--ipstart', 'x.x.x.x']),
    ("trigger_custom: error: the following arguments are required: --triggerstart, --triggerend",
     ['trigger_custom'])
    ])
def test_subcommands(parser, capsys, expect_string, cli_opts):
    try:
        parser.parse_args(cli_opts)
    except SystemExit:
        pass
    assert expect_string in capsys.readouterr().err

def test_validate_trigger_custom(parser, caplog):
    args = parser.parse_args(['trigger_custom', '--triggerstart', '0',
                             '--triggerend', str(SIM_INSTANCES)])
    try:
        MassPnfSim(args).trigger_custom()
    except SystemExit as e:
        assert e.code == 1
    assert "--triggerend value greater than existing instance count" in caplog.text
    caplog.clear()

@pytest.mark.parametrize(("subcommand"), [
    'bootstrap',
    'start',
    'stop',
    'trigger',
    'status'
    ])
def test_count_option(parser, capsys, subcommand):
    try:
        parser.parse_args([subcommand, '--count'])
    except SystemExit:
        pass
    assert f"{subcommand}: error: argument --count: expected one argument" in capsys.readouterr().err

def test_empty(parser, capsys):
    try:
        parser.parse_args([])
    except SystemExit:
        pass
    assert '' is capsys.readouterr().err
    assert '' is capsys.readouterr().out