From c44c2db96e9901a32077a8922e52f1d1219be2cb Mon Sep 17 00:00:00 2001 From: Travis Rhoden Date: Thu, 25 Jun 2015 16:30:11 -0700 Subject: [PATCH] [RM-11742] Add argparse tests for ceph-deploy config Signed-off-by: Travis Rhoden --- ceph_deploy/tests/parser/test_config.py | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 ceph_deploy/tests/parser/test_config.py diff --git a/ceph_deploy/tests/parser/test_config.py b/ceph_deploy/tests/parser/test_config.py new file mode 100644 index 0000000..d71461e --- /dev/null +++ b/ceph_deploy/tests/parser/test_config.py @@ -0,0 +1,61 @@ +import pytest + +from ceph_deploy.cli import get_parser + +SUBCMDS_WITH_ARGS = ['push', 'pull'] + + +class TestParserConfig(object): + + def setup(self): + self.parser = get_parser() + + def test_config_help(self, capsys): + with pytest.raises(SystemExit): + self.parser.parse_args('config --help'.split()) + out, err = capsys.readouterr() + assert 'usage: ceph-deploy config' in out + assert 'positional arguments:' in out + assert 'optional arguments:' in out + + @pytest.mark.parametrize('cmd', SUBCMDS_WITH_ARGS) + def test_config_subcommands_with_args(self, cmd): + self.parser.parse_args(['config'] + ['%s' % cmd] + ['host1']) + + def test_config_invalid_subcommand(self, capsys): + with pytest.raises(SystemExit): + self.parser.parse_args('config bork'.split()) + out, err = capsys.readouterr() + assert 'invalid choice' in err + + @pytest.mark.skipif(reason="http://tracker.ceph.com/issues/12150") + def test_config_push_host_required(self, capsys): + with pytest.raises(SystemExit): + self.parser.parse_args('config push'.split()) + out, err = capsys.readouterr() + assert "error: too few arguments" in err + + def test_config_push_one_host(self): + args = self.parser.parse_args('config push host1'.split()) + assert args.client == ['host1'] + + def test_config_push_multiple_hosts(self): + hostnames = ['host1', 'host2', 'host3'] + args = self.parser.parse_args('config push'.split() + hostnames) + assert args.client == hostnames + + @pytest.mark.skipif(reason="http://tracker.ceph.com/issues/12150") + def test_config_pull_host_required(self, capsys): + with pytest.raises(SystemExit): + self.parser.parse_args('config pull'.split()) + out, err = capsys.readouterr() + assert "error: too few arguments" in err + + def test_config_pull_one_host(self): + args = self.parser.parse_args('config pull host1'.split()) + assert args.client == ['host1'] + + def test_config_pull_multiple_hosts(self): + hostnames = ['host1', 'host2', 'host3'] + args = self.parser.parse_args('config pull'.split() + hostnames) + assert args.client == hostnames -- 2.47.3