]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-11742] Add argparse tests for ceph-deploy config
authorTravis Rhoden <trhoden@redhat.com>
Thu, 25 Jun 2015 23:30:11 +0000 (16:30 -0700)
committerTravis Rhoden <trhoden@redhat.com>
Thu, 25 Jun 2015 23:30:11 +0000 (16:30 -0700)
Signed-off-by: Travis Rhoden <trhoden@redhat.com>
ceph_deploy/tests/parser/test_config.py [new file with mode: 0644]

diff --git a/ceph_deploy/tests/parser/test_config.py b/ceph_deploy/tests/parser/test_config.py
new file mode 100644 (file)
index 0000000..d71461e
--- /dev/null
@@ -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