示例#1
0
    def test_sync(self):
        """Test synchronize workspace."""
        subparser = self.parser.add_subparsers(dest="subcommand_test")
        ws_subcmds = WorkspaceSubcommands(
            "yoda", subparser, self.config
        )
        ws_subcmds.parse()

        args = self.parser.parse_args([
            "yoda", "sync"])

        self.assertEqual("sync", args.action)
示例#2
0
    def test_exec_without_command(self):
        """Test repository execute without subcommand."""
        subparser = self.parser.add_subparsers(dest="subcommand_test")
        ws_subcmds = WorkspaceSubcommands(
            "yoda", subparser, self.config
        )
        ws_subcmds.parse()

        try:
            args = self.parser.parse_args(["yoda"])
            self.assertIsNone(ws_subcmds.execute(args))
        except SystemExit:
            #Raised in Python 2.7.x
            self.assertEqual("2.7", sys.version[:3])
示例#3
0
    def test_parse_add(self):
        """Test parse add subcommands."""
        subparser = self.parser.add_subparsers(dest="subcommand_test")
        ws_subcmds = WorkspaceSubcommands(
            "yoda", subparser, self.config
        )
        ws_subcmds.parse()

        args = self.parser.parse_args([
            "yoda", "add", "repo-name", "-u", "repo-url", "-p", "repo-path"])

        self.assertEqual("add", args.action)
        self.assertEqual("repo-name", args.repo_name)
        self.assertEqual("repo-url", args.url)
        self.assertEqual("repo-path", args.path)
示例#4
0
    def test_execute_add_subcommand(self):
        """Test execute add subcommand."""
        subparser = self.parser.add_subparsers(dest="subcommand")
        ws_subcmds = WorkspaceSubcommands(
            "yoda", subparser, self.config
        )
        ws_subcmds.parse()

        args = self.parser.parse_args(
            ["yoda", "add", "other-repo", "-p",
             "%s/repo-name" % self.directory, "-u", "repo-url"])

        with patch(
                "yoda.subcommand.workspace.clone") as patch_clone:
            self.sandbox.mkdir("tmp")
            ws_subcmds.execute(args)
            patch_clone.assert_called_once_with(
                "repo-url",
                "%s/repo-name" % self.directory)
示例#5
0
    def setUp(self):
        """Setup test suite."""
        super(TestWorkspacesSubcommands, self).setUp()
        self.subcommand = WorkspaceSubcommands(
            "yoda", self.subparser, self.config
        )

        self.config_data = {
            "workspaces": {
                "yoda": {
                    "path": self.sandbox.path
                }
            }
        }

        self.config.update(self.config_data)
示例#6
0
    def test_execute_add_subcommand_repo_already_exists(self):
        """Test execute add subcommands when repo name already exists."""
        subparser = self.parser.add_subparsers(dest="subcommand")
        ws_subcmds = WorkspaceSubcommands(
            "yoda", subparser, self.config
        )
        ws_subcmds.parse()

        args = self.parser.parse_args(["yoda", "add", "repo-name"])
        self.sandbox.mkdir("tmp")
        ws_subcmds.execute(args)
        self.assertTrue(os.path.exists(self.directory + "/repo-name"))
        self.assertRaises(ValueError, lambda: ws_subcmds.execute(args))
示例#7
0
    def test_execute_remove_subcommad(self):
        """Test execute remove subcommands."""
        self.config_data["workspaces"]["yoda"]["repositories"] = {
            "repo-name": self.directory + "/repo-name"
        }
        subparser = self.parser.add_subparsers(dest="subcommand")
        ws_subcmds = WorkspaceSubcommands(
            "yoda", subparser, self.config
        )
        ws_subcmds.parse()

        args = self.parser.parse_args(["yoda", "remove", "repo-name"])
        ws_subcmds.execute(args)
        self.assertFalse(os.path.exists(self.directory + "/repo-name"))

        args = self.parser.parse_args(["yoda", "remove", "1377"])
        self.assertRaises(ValueError, lambda: ws_subcmds.execute(args))
示例#8
0
    def test_execute_sync_subcommand(self):
        """Test execute sync subcommand."""
        self.config_data["workspaces"]["yoda"]["repositories"] = {
            "repo-name": self.directory + "/repo-name"
        }
        subparser = self.parser.add_subparsers(dest="subcommand")
        config = self.config
        ws_subcmds = WorkspaceSubcommands(
            "yoda", subparser, config
        )
        ws_subcmds.parse()

        args = self.parser.parse_args(
            ["yoda", "sync", "yoda"]
        )
        self.sandbox.mkdir("tmp")

        self.assertFalse(ws_subcmds.execute(args))
        with patch(
                "yoda.subcommand.workspace.Repository.__init__",
                return_value=None):
            ws_subcmds.execute(args)
示例#9
0
class TestWorkspacesSubcommands(SubcommandTestHelper):
    """Test suite for workspaces subcommands setup."""
    config_data = None
    directory = None

    def setUp(self):
        """Setup test suite."""
        super(TestWorkspacesSubcommands, self).setUp()
        self.subcommand = WorkspaceSubcommands(
            "yoda", self.subparser, self.config
        )

        self.config_data = {
            "workspaces": {
                "yoda": {
                    "path": self.sandbox.path
                }
            }
        }

        self.config.update(self.config_data)

    def test_parse_add(self):
        """Test parse add subcommands."""
        self.assert_subcommand_parsing(
            ["yoda", "add", "repo-name", "-u", "repo-url", "-p", "repo-path"],
            {
                "action": "add",
                "repo_name": "repo-name",
                "url": "repo-url",
                "path": "repo-path"
            }
        )

    def test_parse_remove(self):
        """Test parse remove subcommands."""
        self.assert_subcommand_parsing(
            ["yoda", "remove", "repo-name"], {
                "action": "remove",
                "repo_name": "repo-name"}
        )

    def test_parse_sync(self):
        """Test parse sync subcommands."""
        self.assert_subcommand_parsing(
            ["yoda", "sync"], {"action": "sync"})

    def test_exec_without_command(self):
        """Test repository execute without subcommand."""
        self.subcommand.parse()

        try:
            args = self.parser.parse_args(["yoda"])
            self.assertIsNone(self.subcommand.execute(args))
        except SystemExit:
            # Raised in Python 2.7.x
            self.assertEqual("2.7", sys.version[:3])

    def test_execute_add_subcommand_repo_already_exists(self):
        """Test execute add subcommands when repo name already exists."""
        self.subcommand.parse()

        args = self.parser.parse_args(["yoda", "add", "repo-name"])
        self.sandbox.mkdir("tmp")
        self.subcommand.execute(args)
        self.assertTrue(os.path.exists(self.sandbox.path + "/repo-name"))
        self.assertRaises(ValueError, lambda: self.subcommand.execute(args))

    def test_execute_add_subcommand_raises_exception(self):
        """Test execute add subcommand raises exception."""
        self.subcommand.parse()

        args = self.parser.parse_args(
            ["yoda", "add", "other-repo", "-p",
             "%s/repo-name" % self.sandbox.path, "-u", "repo-url"])

        with patch(
                "yoda.workspace.clone") as patch_clone:
            self.sandbox.mkdir("tmp")
            self.assertRaises(RepositoryError, self.subcommand.execute, args)
            patch_clone.assert_called_once_with(
                "repo-url",
                "%s/repo-name" % self.sandbox.path)

    def test_execute_add_subcommand(self):
        """Test execute add subcommand."""
        self.subcommand.parse()
        args = self.parser.parse_args(
            ["yoda", "add", "other-repo", "-p",
             "%s/repo-name" % self.sandbox.path])

        with LogCapture() as lcap:
            self.subcommand.execute(args)

        lcap.check(
            ("yoda.subcommand.workspace", "INFO",
             "Repository `other-repo` added to `yoda` workspace."))

    def test_execute_add_subcommand_call_slashes2dash(self):
        """Test execute add subcommand call slashes2dash function."""
        self.subcommand.parse()
        args = self.parser.parse_args(
            ["yoda", "add", "my_repository", "-p",
             "%s/repo-name" % self.sandbox.path])

        with patch("yoda.subcommand.workspace.slashes2dash",
                   return_value="repo-name") as s2d:
            self.subcommand.execute(args)
        s2d.assert_called_once_with("my_repository")

    @patch("%s.input" % builtins_module,
           Mock(side_effect=["n", "y"]))
    def test_execute_remove_subcommand(self):
        """Test execute remove subcommand raises exception."""
        self.subcommand.parse()
        self.config_data["workspaces"]["yoda"]["repositories"] = {
            "repo-name": self.sandbox.path + "/repo-name"
        }

        args = self.parser.parse_args(["yoda", "remove", "repo-name"])
        with LogCapture() as lcap:
            self.subcommand.execute(args)
        self.assertFalse(os.path.exists(self.sandbox.path + "/repo-name"))
        lcap.check(
            ("yoda.subcommand.workspace", "INFO",
             "Repository `repo-name` removed from `yoda` workspace."))

    def test_execute_remove_subcommand_when_not_exists(self):
        """Test execute remove subcommand when repository doesn't exists."""
        self.subcommand.parse()
        self.config_data["workspaces"]["yoda"]["repositories"] = {
            "repo-name": self.sandbox.path + "/repo-name"
        }
        args = self.parser.parse_args(["yoda", "remove", "1377"])
        self.assertRaises(ValueError, lambda: self.subcommand.execute(args))

    @patch("%s.input" % builtins_module,
           Mock(side_effect=["n", "y"]))
    def test_execute_remove_subcommand_call_slashes2dash(self):
        """
        Test execute remove subcommand call slashes2dash function
        for name argument.
        """
        self.subcommand.parse()
        self.config_data["workspaces"]["yoda"]["repositories"] = {
            "repo-name": self.sandbox.path + "/repo-name"
        }
        args = self.parser.parse_args(["yoda", "remove", "repo-name"])

        with patch("yoda.subcommand.workspace.slashes2dash",
                   return_value="repo-name") as s2d:
            self.subcommand.execute(args)

        s2d.assert_called_once_with("repo-name")

    def test_execute_sync_subcommand(self):
        """Test execute sync subcommand."""
        self.subcommand.parse()
        self.config_data["workspaces"]["yoda"]["repositories"] = {
            "repo-name": self.sandbox.path + "/repo-name"
        }

        args = self.parser.parse_args(
            ["yoda", "sync", "yoda"])

        self.assertFalse(self.subcommand.execute(args))
        with patch(
                "yoda.subcommand.workspace.Ws.sync",
                return_value=None):
            with LogCapture() as lcap:
                self.subcommand.execute(args)

        lcap.check(
            ("yoda.subcommand.workspace", "INFO",
             "Workspace `yoda` synchronized."))