Example #1
0
    def helper_test_checkout_repos(self,
                                   source,
                                   target,
                                   commands,
                                   branch=None,
                                   verbose=True):
        """ test_checkout_repos common test code """
        local = LocalHost()

        # Test with non-existing target
        self.assertFalse(os.path.exists(target))
        with patch("dsi.common.host.mkdir_p") as mock_mkdir_p, patch(
                "dsi.common.local_host.LocalHost.exec_command"
        ) as mock_exec_command:
            local.checkout_repos(source,
                                 target,
                                 verbose=verbose,
                                 branch=branch)
            mock_mkdir_p.assert_called_with(self.parent_dir)
            if len(commands) == 1:
                mock_exec_command.assert_called_once()
                mock_exec_command.assert_called_with(commands[0])
            else:
                for command in commands:
                    mock_exec_command.assert_any_call(command)
Example #2
0
    def test_checkout_repos_existing_target(self):

        # Test with existing target that is a git repository
        local = LocalHost()

        source = "https://github.com/mongodb/stitch-js-sdk.git"
        target = os.path.join(self.parent_dir, "stitch-js-sdk")
        command = ["cd", target, "&&", "git", "status"]
        with patch("dsi.common.host.os.path.isdir") as mock_isdir, patch(
                "dsi.common.host.mkdir_p") as mock_mkdir_p, patch(
                    "dsi.common.local_host.LocalHost.exec_command"
                ) as mock_exec_command:
            mock_isdir.return_value = True
            mock_exec_command.return_value = 0
            local.checkout_repos(source, target)
            mock_mkdir_p.assert_not_called()
            mock_exec_command.assert_called_once()
            mock_exec_command.assert_called_with(command)