def test_alert_linux(self, echo_mock, shell_mock):
        config = CliConfig()

        config.alert("hello")
        echo_mock.assert_called_once()
        shell_mock.assert_called_once()
        self.assertIn("notify-send", shell_mock.call_args[0][0])
    def test_alert__disabled(self, echo_mock, shell_mock):
        config = CliConfig()
        config.project_config.dev_config__no_alert = True

        config.alert("hello")
        echo_mock.assert_not_called()
        shell_mock.assert_not_called()
    def test_check_org_overwrite_non_scratch_exists(self):
        config = CliConfig()
        config.keychain.get_org = mock.Mock(
            return_value=OrgConfig({"scratch": False}, "test"))

        with self.assertRaises(click.ClickException):
            config.check_org_overwrite("test")
    def test_alert_osx(self, echo_mock, shell_mock):
        config = CliConfig()

        config.alert("hello")
        echo_mock.assert_called_once()
        shell_mock.assert_called_once()
        self.assertIn("osascript", shell_mock.call_args[0][0])
    def test_get_org_missing(self):
        config = CliConfig()
        config.keychain = mock.Mock()
        config.keychain.get_org.return_value = None

        with self.assertRaises(click.UsageError):
            org_name, org_config_result = config.get_org("test",
                                                         fail_if_missing=True)
    def test_get_org_default(self):
        config = CliConfig()
        config.keychain = mock.Mock()
        org_config = OrgConfig({}, "test")
        config.keychain.get_default_org.return_value = ("test", org_config)

        org_name, org_config_result = config.get_org()
        self.assertEqual("test", org_name)
        self.assertIs(org_config, org_config_result)
    def test_check_org_expired(self, confirm):
        config = CliConfig()
        config.keychain = mock.Mock()
        org_config = OrgConfig(
            {
                "scratch": True,
                "date_created": date.today() - timedelta(days=2),
                "expired": True,
            },
            "test",
        )
        confirm.return_value = True

        config.check_org_expired("test", org_config)
        config.keychain.create_scratch_org.assert_called_once()
    def test_check_org_expired_decline(self, confirm):
        config = CliConfig()
        config.keychain = mock.Mock()
        org_config = OrgConfig(
            {
                "scratch": True,
                "date_created": date.today() - timedelta(days=2),
                "expired": True,
            },
            "test",
        )
        confirm.return_value = False

        with self.assertRaises(click.ClickException):
            config.check_org_expired("test", org_config)
Beispiel #9
0
 def project_config(self):
     if self._project_config is None:
         if CURRENT_TASK and isinstance(CURRENT_TASK, Robot):
             # If CumulusCI is running a task, use that task's config
             return CURRENT_TASK.project_config
         else:
             logger.console('Initializing CumulusCI config\n')
             self._project_config = CliConfig().project_config
     return self._project_config
Beispiel #10
0
def load_config(load_project_config=True, load_keychain=True):
    try:
        config = TEST_CONFIG or CliConfig(
            load_project_config=load_project_config,
            load_keychain=load_keychain)
        config.check_cumulusci_version()
    except click.UsageError as e:
        click.echo(str(e))
        sys.exit(1)
    return config
Beispiel #11
0
def main(ctx):
    """Main CumulusCI CLI entry point.

    This runs as the first step in processing any CLI command.
    """
    check_latest_version()
    init_logger()

    try:
        config = CliConfig()
    except click.UsageError as e:
        click.echo(str(e))
        sys.exit(1)

    config.check_cumulusci_version()

    # Attach the config object to the click context
    # so it can be accessed by other commands using `click.pass_obj`
    ctx.obj = config
    def test_init(self):
        config = CliConfig()

        for key in {
                "cumulusci", "tasks", "flows", "services", "orgs", "project"
        }:
            self.assertIn(key, config.global_config.config)
        self.assertEqual("CumulusCI", config.project_config.project__name)
        for key in {"services", "orgs", "app"}:
            self.assertIn(key, config.keychain.config)
        self.assertIn(config.project_config.repo_root, sys.path)
Beispiel #13
0
    def test_flow_run_org_delete_error(self, echo):
        org_config = mock.Mock(scratch=True, config={})
        org_config.delete_org.side_effect = Exception
        config = CliConfig(
            config={
                "flows": {
                    "test": {
                        "steps": {
                            1: {
                                "task": "test_task"
                            }
                        }
                    }
                },
                "tasks": {
                    "test_task": {
                        "class_path": "cumulusci.cli.tests.test_cci.DummyTask",
                        "description": "Test Task",
                    }
                },
            },
            load_keychain=False,
        )
        config.get_org = mock.Mock(return_value=("test", org_config))
        DummyTask._run_task = mock.Mock()

        run_click_command(
            cci.flow_run,
            config=config,
            flow_name="test",
            org="test",
            delete_org=True,
            debug=False,
            o=None,
            skip=(),
            no_prompt=True,
        )

        echo.assert_any_call(
            "Scratch org deletion failed.  Ignoring the error below to complete the flow:"
        )
Beispiel #14
0
def main(ctx):
    try:
        check_latest_version()
    except requests.exceptions.RequestException as e:
        click.echo('Error checking cci version:')
        click.echo(e.message)

    try:
        config = CliConfig()
    except click.UsageError as e:
        click.echo(e.message)
        sys.exit(1)
    ctx.obj = config
Beispiel #15
0
    def test_flow_run(self):
        org_config = mock.Mock(scratch=True, config={})
        config = CliConfig(
            config={
                "flows": {
                    "test": {
                        "steps": {
                            1: {
                                "task": "test_task"
                            }
                        }
                    }
                },
                "tasks": {
                    "test_task": {
                        "class_path": "cumulusci.cli.tests.test_cci.DummyTask",
                        "description": "Test Task",
                    }
                },
            },
            load_keychain=False,
        )
        config.get_org = mock.Mock(return_value=("test", org_config))
        DummyTask._run_task = mock.Mock()

        run_click_command(
            cci.flow_run,
            config=config,
            flow_name="test",
            org="test",
            delete_org=True,
            debug=False,
            o=[("test_task__color", "blue")],
            skip=(),
            no_prompt=True,
        )

        DummyTask._run_task.assert_called_once()
        org_config.delete_org.assert_called_once()
Beispiel #16
0
    def test_flow_run_unexpected_exception(self, handle_sentry_event):
        org_config = mock.Mock(config={})
        config = CliConfig(
            config={
                "flows": {
                    "test": {
                        "steps": {
                            1: {
                                "task": "test_task"
                            }
                        }
                    }
                },
                "tasks": {
                    "test_task": {
                        "class_path": "cumulusci.cli.tests.test_cci.DummyTask",
                        "description": "Test Task",
                    }
                },
            },
            load_keychain=False,
        )
        config.get_org = mock.Mock(return_value=("test", org_config))
        DummyTask._run_task = mock.Mock(side_effect=Exception)

        with self.assertRaises(Exception):
            run_click_command(
                cci.flow_run,
                config=config,
                flow_name="test",
                org="test",
                delete_org=False,
                debug=False,
                o=None,
                skip=(),
                no_prompt=True,
            )

        handle_sentry_event.assert_called_once()
Beispiel #17
0
    def test_flow_run_usage_error(self):
        org_config = mock.Mock(config={})
        config = CliConfig(
            config={
                "flows": {
                    "test": {
                        "steps": {
                            1: {
                                "task": "test_task"
                            }
                        }
                    }
                },
                "tasks": {
                    "test_task": {
                        "class_path": "cumulusci.cli.tests.test_cci.DummyTask",
                        "description": "Test Task",
                    }
                },
            },
            load_keychain=False,
        )
        config.get_org = mock.Mock(return_value=("test", org_config))
        DummyTask._run_task = mock.Mock(side_effect=TaskOptionsError)

        with self.assertRaises(click.UsageError):
            run_click_command(
                cci.flow_run,
                config=config,
                flow_name="test",
                org="test",
                delete_org=False,
                debug=False,
                o=None,
                skip=(),
                no_prompt=True,
            )
    def test_load_project_config_error(self, load_proj_cfg_mock):
        load_proj_cfg_mock.side_effect = ConfigError

        with self.assertRaises(click.UsageError):
            CliConfig()
Beispiel #19
0
    """
    def decorator(f):
        def new_func(*args, **kwargs):
            ctx = click.get_current_context()
            return ctx.invoke(f, obj, *args[1:], **kwargs)
        return click.decorators.update_wrapper(new_func, f)
    return decorator

try:
    check_latest_version()
except requests.exceptions.RequestException as e:
    click.echo('Error checking cci version:')
    click.echo(e.message) 

try:
    CLI_CONFIG = CliConfig()
except click.UsageError as e:
    click.echo(e.message)
    sys.exit(1)

pass_config = make_pass_instance_decorator(CLI_CONFIG)

def check_connected_app(config):
    check_keychain(config)
    if not config.keychain.get_connected_app():
        raise click.UsageError(
            "Please use the 'org config_connected_app' command to configure the OAuth Connected App to use for this project's keychain")


def check_keychain(config):
    check_project_config(config)
Beispiel #20
0
 def _init_config(self):
     config = CliConfig()
     return config
    def test_check_org_overwrite_not_found(self):
        config = CliConfig()
        config.keychain.get_org = mock.Mock(side_effect=OrgNotFound)

        self.assertTrue(config.check_org_overwrite("test"))
    def test_check_cumulusci_version(self):
        config = CliConfig()
        config.project_config.minimum_cumulusci_version = "999"

        with self.assertRaises(click.UsageError):
            config.check_cumulusci_version()
 def test_alert__os_error(self, echo_mock, shell_mock):
     shell_mock.side_effect = OSError
     config = CliConfig()
     config.alert("hello")
     echo_mock.assert_called_once()
     shell_mock.assert_called_once()
 def test_load_keychain__no_key(self):
     with mock.patch.dict(os.environ, {"CUMULUSCI_KEY": ""}):
         with self.assertRaises(click.UsageError):
             config = CliConfig()
Beispiel #25
0
 def project_config(self):
     if self._project_config is None:
         self._project_config = CliConfig().project_config
     return self._project_config
 def test_load_project_config_no_file(self, load_proj_cfg_mock):
     load_proj_cfg_mock.side_effect = ProjectConfigNotFound
     with self.assertRaises(click.UsageError):
         CliConfig()
    def test_load_project_not_in_project(self, load_proj_cfg_mock):
        load_proj_cfg_mock.side_effect = NotInProject

        with self.assertRaises(click.UsageError):
            CliConfig()