Example #1
0
    def setUp(self):
        """Setup test suite."""
        self.subcommand = Status()
        self.subcommand_str = "status"
        super(TestSubcommandStatus, self).setUp()

        config_data = {
            "workspaces": {
                "yoda": {
                    "path": "/yoda",
                    "repositories": {
                        "yoda": "/project/yoda"
                    }
                }
            }
        }
        self.config.update(config_data)
Example #2
0
    def setUp(self):
        """Setup test suite."""
        self.parser = argparse.ArgumentParser(prog="yoda_test")
        self.subparser = self.parser.add_subparsers(dest="subcommand_test")

        self.status = Status()
        config_data = {
            "workspaces": {
                "yoda": {
                    "path": "/yoda",
                    "repositories": {
                        "yoda": "/project/yoda"
                    }
                }
            }
        }

        self.sandbox = Sandbox()
        self.config = Config(self.sandbox.path + "/config")
        self.config.update(config_data)
        self.status.setup("status", self.config, self.subparser)
Example #3
0
class TestSubcommandStatus(unittest.TestCase):
    """Status subcommand test suite."""
    sandbox = None
    config = None
    parser = None
    subparser = None
    status = None

    def setUp(self):
        """Setup test suite."""
        self.parser = argparse.ArgumentParser(prog="yoda_test")
        self.subparser = self.parser.add_subparsers(dest="subcommand_test")

        self.status = Status()
        config_data = {
            "workspaces": {
                "yoda": {
                    "path": "/yoda",
                    "repositories": {
                        "yoda": "/project/yoda"
                    }
                }
            }
        }

        self.sandbox = Sandbox()
        self.config = Config(self.sandbox.path + "/config")
        self.config.update(config_data)
        self.status.setup("status", self.config, self.subparser)

    def tearDown(self):
        """Tear down test suite."""
        self.parser = None
        self.status = None

    def test_parse_status(self):
        """Test parse status subcommand."""
        self.status.parse()

        args = self.parser.parse_args(["status", "ws1/repo1"])

        self.assertEqual("status", args.subcommand_test)
        self.assertEqual("ws1/repo1", args.name)

        args = self.parser.parse_args(["status", "--all"])

        self.assertEqual("status", args.subcommand_test)
        self.assertEqual(True, args.all)

        self.assertRaises(
            SystemExit,
            self.parser.parse_args, ["status", "--all", "ws1/repo1"]
        )

    def test_exec_status_workspace_only(self):
        """Test exec status subcommand."""
        args = Mock()
        args.name = "foo/bar"

        mock_path = {"foo/bar": "/tmp/foo/bar"}

        self.status.print_status = Mock()

        with patch("yoda.subcommand.status.find_path",
                   return_value=mock_path) as patch_fp:
            self.status.execute(args)
            patch_fp.assert_called_once_with("foo/bar", self.status.config)
            self.status.print_status.assert_called_once_with(
                "foo/bar", "/tmp/foo/bar")

    def test_exec_status_all_workspaces(self):
        """Test exec with all workspaces."""
        args = Mock()
        args.name = None
        args.all = True

        mock_path = {"foo/bar": "/tmp/foo/bar"}

        self.status.print_status = Mock()

        with patch("yoda.subcommand.status.find_path",
                   return_value=mock_path):
            self.status.execute(args)

    def test_exec_status_no_matches(self):
        """Test exec status subcommand with no matches."""
        args = Mock()
        args.name = "foobar"

        self.status.logger = Mock()
        self.status.print_status = Mock()

        with patch("yoda.subcommand.status.find_path", return_value={}):
            self.assertFalse(self.status.execute(args))
            self.status.logger.error.assert_called_once_with(
                "No matches for `foobar`")

    def test_print_status(self):
        """Test print_status."""
        self.status.logger = Mock()
        with patch("yoda.subcommand.status.Repository"):
            self.status.print_status("foo", "bar")
            self.status.logger.info.assert_has_calls(
                [call("\033[32m=> [foo] bar\033[0m")])
Example #4
0
class TestSubcommandStatus(SubcommandTestHelper):
    """Status subcommand test suite."""

    def setUp(self):
        """Setup test suite."""
        self.subcommand = Status()
        self.subcommand_str = "status"
        super(TestSubcommandStatus, self).setUp()

        config_data = {
            "workspaces": {
                "yoda": {
                    "path": "/yoda",
                    "repositories": {
                        "yoda": "/project/yoda"
                    }
                }
            }
        }
        self.config.update(config_data)

    def test_parse_status(self):
        """Test parse status subcommand."""
        self.assert_subcommand_parsing(["status", "ws1/repo1"], {
            "subcommand": "status",
            "name": "ws1/repo1"})

    def test_parse_status_all(self):
        """Test show status of all workspaces."""
        self.assert_subcommand_parsing(["status", "--all"], {
            "subcommand": "status",
            "all": True})

    def test_parse_status_raises_error(self):
        """
        Test show status raises error when --all specifier
        with workspace or repository name.
        """
        self.assert_subcommand_parsing_raises_error(
            ["status", "--all", "ws1/repo1"], SystemExit)

    def test_exec_status_workspace_only(self):
        """Test exec status subcommand."""
        args = Mock()
        args.name = "foo/bar"

        mock_path = {"foo/bar": "/tmp/foo/bar"}

        self.subcommand.print_status = Mock()

        with patch("yoda.subcommand.status.find_path",
                   return_value=mock_path) as patch_fp:
            self.subcommand.execute(args)
            patch_fp.assert_called_once_with("foo/bar", self.subcommand.config)
            self.subcommand.print_status.assert_called_once_with(
                "foo/bar", "/tmp/foo/bar")

    def test_exec_status_all_workspaces(self):
        """Test exec with all workspaces."""
        args = Mock()
        args.name = None
        args.all = True

        mock_path = {"foo/bar": "/tmp/foo/bar"}

        self.subcommand.print_status = Mock()

        with patch("yoda.subcommand.status.find_path",
                   return_value=mock_path):
            self.subcommand.execute(args)

    def test_exec_status_no_matches(self):
        """Test exec status subcommand with no matches."""
        args = Mock()
        args.name = "foobar"

        self.subcommand.print_status = Mock()
        with patch("yoda.subcommand.status.find_path", return_value={}):
            with LogCapture() as lcap:
                self.assertFalse(self.subcommand.execute(args))

        lcap.check(("yoda.subcommand.status", "ERROR",
                    "No matches for `foobar`"))

    def test_print_status(self):
        """Test print_status."""
        with patch("yoda.subcommand.status.Repository"):
            with LogCapture() as lcap:
                self.subcommand.print_status("foo", "bar")

        lcap.check(("yoda.subcommand.status", "INFO",
                    "\033[32m=> [foo] bar\033[0m"))

    def test_print_status_log_error_message(self):
        """Test that print_status logs the error message."""
        with LogCapture() as lcap:
            self.subcommand.print_status("foo", "/path/doesnot/exists")

        lcap.check(("yoda.subcommand.status", "INFO",
                    "\033[32m=> [foo] /path/doesnot/exists\033[0m"),
                   ("yoda.subcommand.status", "ERROR",
                    "Path doesn't exists or isn't a directory "
                    "(/path/doesnot/exists)\n"))