Пример #1
0
 def test_load_project_config_no_config(self, mock_class):
     mock_class.return_value = self.tempdir_home
     os.mkdir(os.path.join(self.tempdir_project, ".git"))
     os.chdir(self.tempdir_project)
     global_config = YamlGlobalConfig()
     with self.assertRaises(ProjectConfigNotFound):
         config = YamlProjectConfig(global_config)
Пример #2
0
 def test_load_global_config_no_local(self, mock_class):
     mock_class.return_value = self.tempdir_home
     config = YamlGlobalConfig()
     with open(__location__ + "/../../cumulusci.yml",
               "r") as f_expected_config:
         expected_config = yaml.load(f_expected_config)
     self.assertEquals(config.config, expected_config)
Пример #3
0
    def test_load_global_config_empty_local(self, mock_class):
        self._create_global_config_local('')
        mock_class.return_value = self.tempdir_home

        config = YamlGlobalConfig()
        with open(__location__ + '/../../cumulusci.yml', 'r') as f_expected_config:
            expected_config = yaml.load(f_expected_config)
        self.assertEquals(config.config, expected_config)
Пример #4
0
    def test_repo_commit(self, mock_class):
        mock_class.return_value = self.tempdir_home
        os.mkdir(os.path.join(self.tempdir_project, ".git"))
        self._create_git_config()

        # create valid project config file
        self._create_project_config()

        os.chdir(self.tempdir_project)
        global_config = YamlGlobalConfig()
        config = YamlProjectConfig(global_config)
        self.assertEquals(config.repo_commit, self.current_commit)
Пример #5
0
    def test_load_global_config_with_local(self, mock_class):
        local_yaml = 'tasks:\n    newtesttask:\n        description: test description'
        self._create_global_config_local(local_yaml)
        mock_class.return_value = self.tempdir_home

        config = YamlGlobalConfig()
        with open(__location__ + '/../../cumulusci.yml', 'r') as f_expected_config:
            expected_config = yaml.load(f_expected_config)
        expected_config['tasks']['newtesttask'] = {}
        expected_config['tasks']['newtesttask'][
            'description'] = 'test description'
        self.assertEquals(config.config, expected_config)        
Пример #6
0
    def test_repo_owner(self, mock_class):
        mock_class.return_value = self.tempdir_home
        os.mkdir(os.path.join(self.tempdir_project, '.git'))
        self._create_git_config()

        # create valid project config file
        self._create_project_config()

        os.chdir(self.tempdir_project)
        global_config = YamlGlobalConfig()
        config = YamlProjectConfig(global_config)
        self.assertEquals(config.repo_owner, 'TestOwner')
Пример #7
0
    def test_load_project_config_valid_config(self, mock_class):
        mock_class.return_value = self.tempdir_home
        os.mkdir(os.path.join(self.tempdir_project, '.git'))
        self._create_git_config()

        # create valid project config file
        self._create_project_config()

        os.chdir(self.tempdir_project)
        global_config = YamlGlobalConfig()
        config = YamlProjectConfig(global_config)
        self.assertEquals(config.project__package__name, 'TestProject')
        self.assertEquals(config.project__package__namespace, 'testproject')
Пример #8
0
    def test_load_global_config_with_local(self, mock_class):
        local_yaml = "tasks:\n    newtesttask:\n        description: test description"
        self._create_global_config_local(local_yaml)
        mock_class.return_value = self.tempdir_home

        config = YamlGlobalConfig()
        with open(__location__ + "/../../cumulusci.yml",
                  "r") as f_expected_config:
            expected_config = yaml.load(f_expected_config)
        expected_config["tasks"]["newtesttask"] = {}
        expected_config["tasks"]["newtesttask"][
            "description"] = "test description"
        self.assertEquals(config.config, expected_config)
Пример #9
0
    def test_load_project_config_empty_config(self, mock_class):
        mock_class.return_value = self.tempdir_home
        os.mkdir(os.path.join(self.tempdir_project, ".git"))
        self._create_git_config()
        # create empty project config file
        filename = os.path.join(self.tempdir_project,
                                YamlProjectConfig.config_filename)
        content = ""
        self._write_file(filename, content)

        os.chdir(self.tempdir_project)
        global_config = YamlGlobalConfig()
        config = YamlProjectConfig(global_config)
        self.assertEquals(config.config_project, {})
Пример #10
0
    def test_load_project_config_valid_config(self, mock_class):
        mock_class.return_value = self.tempdir_home
        os.mkdir(os.path.join(self.tempdir_project, ".git"))
        self._create_git_config()
        local_yaml = "tasks:\n    newtesttask:\n        description: test description"
        self._create_global_config_local(local_yaml)

        # create valid project config file
        self._create_project_config()

        os.chdir(self.tempdir_project)
        global_config = YamlGlobalConfig()
        config = YamlProjectConfig(global_config)
        self.assertEquals(config.project__package__name, "TestProject")
        self.assertEquals(config.project__package__namespace, "testproject")
Пример #11
0
    def test_load_additional_yaml(self, mock_class):
        mock_class.return_value = self.tempdir_home
        os.mkdir(os.path.join(self.tempdir_project, ".git"))
        self._create_git_config()

        # create valid project config file
        self._create_project_config()

        # create local project config file
        content = "project:\n" + "    package:\n" + "        api_version: 10\n"

        os.chdir(self.tempdir_project)
        global_config = YamlGlobalConfig()
        config = YamlProjectConfig(global_config, additional_yaml=content)
        self.assertNotEqual(config.config_additional_yaml, {})
        self.assertEqual(config.project__package__api_version, 10)
Пример #12
0
    def test_load_project_config_local(self, mock_class):
        mock_class.return_value = self.tempdir_home
        os.mkdir(os.path.join(self.tempdir_project, '.git'))
        self._create_git_config()

        # create valid project config file
        self._create_project_config()

        # create local project config file
        content = ('project:\n' + '    package:\n' +
                   '        api_version: 10\n')
        self._create_project_config_local(content)

        os.chdir(self.tempdir_project)
        global_config = YamlGlobalConfig()
        config = YamlProjectConfig(global_config)
        self.assertNotEqual(config.config_project_local, {})
        self.assertEqual(config.project__package__api_version, 10)
Пример #13
0
class CliConfig(object):

    def __init__(self):
        self.global_config = None
        self.project_config = None
        self.keychain = None

        init_logger()
        self._load_global_config()
        self._load_project_config()
        self._load_keychain()
        self._add_repo_to_path()

    def _add_repo_to_path(self):
        if self.project_config:
            sys.path.append(self.project_config.repo_root)

    def _load_global_config(self):
        try:
            self.global_config = YamlGlobalConfig()
        except NotInProject as e:
            raise click.UsageError(e.message)

    def _load_project_config(self):
        try:
            self.project_config = self.global_config.get_project_config()
        except ProjectConfigNotFound:
            pass
        except NotInProject as e:
            raise click.UsageError(e.message)
        except ConfigError as e:
            raise click.UsageError('Config Error: {}'.format(e.message))

    def _load_keychain(self):
        self.keychain_key = os.environ.get('CUMULUSCI_KEY')
        if self.project_config:
            keychain_class = os.environ.get(
                'CUMULUSCI_KEYCHAIN_CLASS',
                self.project_config.cumulusci__keychain,
            )
            self.keychain_class = import_class(keychain_class)
            self.keychain = self.keychain_class(
                self.project_config, self.keychain_key)
            self.project_config.set_keychain(self.keychain)
Пример #14
0
class CliConfig(object):
    def __init__(self):
        self.global_config = None
        self.project_config = None
        self.keychain = None

        init_logger()
        self._load_global_config()
        self._load_project_config()
        self._load_keychain()
        self._add_repo_to_path()

    def _add_repo_to_path(self):
        if self.project_config:
            sys.path.append(self.project_config.repo_root)

    def _load_global_config(self):
        try:
            self.global_config = YamlGlobalConfig()
        except NotInProject as e:
            raise click.UsageError(e.message)

    def _load_project_config(self):
        try:
            self.project_config = self.global_config.get_project_config()
        except ProjectConfigNotFound:
            pass
        except NotInProject as e:
            raise click.UsageError(e.message)

    def _load_keychain(self):
        self.keychain_key = os.environ.get('CUMULUSCI_KEY')
        if self.project_config:
            keychain_class = os.environ.get(
                'CUMULUSCI_KEYCHAIN_CLASS',
                self.project_config.cumulusci__keychain,
            )
            self.keychain_class = import_class(keychain_class)
            self.keychain = self.keychain_class(self.project_config, self.keychain_key)
            self.project_config.set_keychain(self.keychain)
Пример #15
0
 def test_load_project_config_no_config(self, mock_class):
     mock_class.return_value = self.tempdir_home
     os.mkdir(os.path.join(self.tempdir_project, '.git'))
     os.chdir(self.tempdir_project)
     global_config = YamlGlobalConfig()
     config = YamlProjectConfig(global_config)
Пример #16
0
 def _load_global_config(self):
     try:
         self.global_config = YamlGlobalConfig()
     except NotInProject as e:
         raise click.UsageError(e.message)
Пример #17
0
class CliConfig(object):
    def __init__(self):
        self.global_config = None
        self.project_config = None
        self.keychain = None

        self._load_global_config()
        self._load_project_config()
        self._load_keychain()
        self._add_repo_to_path()

    def _add_repo_to_path(self):
        if self.project_config:
            sys.path.append(self.project_config.repo_root)

    def _load_global_config(self):
        self.global_config = YamlGlobalConfig()

    def _load_project_config(self):
        try:
            self.project_config = self.global_config.get_project_config()
        except (
            ProjectConfigNotFound,
            NotInProject,
        ) as e:  # not in a git repo or cci project (respectively)
            raise click.UsageError(str(e))
        except ConfigError as e:
            raise click.UsageError("Config Error: {}".format(str(e)))

    def _load_keychain(self):
        self.keychain_key = os.environ.get("CUMULUSCI_KEY")
        if self.project_config:
            keychain_class = os.environ.get(
                "CUMULUSCI_KEYCHAIN_CLASS", self.project_config.cumulusci__keychain
            )
            self.keychain_class = import_class(keychain_class)
            try:
                self.keychain = self.keychain_class(
                    self.project_config, self.keychain_key
                )
            except (KeychainKeyNotFound, ConfigError) as e:
                raise click.UsageError("Keychain Error: {}".format(str(e)))
            self.project_config.set_keychain(self.keychain)

    def alert(self, message="We need your attention!"):
        if self.project_config and self.project_config.dev_config__no_alert:
            return
        click.echo("\a")
        try:
            call(
                [
                    "osascript",
                    "-e",
                    'display notification "{}" with title "{}"'.format(
                        message.replace('"', r"\"").replace("'", r"\'"), "CumulusCI"
                    ),
                ]
            )
        except OSError:
            pass  # we don't have osascript, probably.

    def get_org(self, org_name=None, fail_if_missing=True):
        if org_name:
            org_config = self.keychain.get_org(org_name)
        else:
            org_name, org_config = self.keychain.get_default_org()
        if org_config:
            org_config = self.check_org_expired(org_name, org_config)
        elif fail_if_missing:
            raise click.UsageError("No org specified and no default org set.")
        return org_name, org_config

    def check_org_expired(self, org_name, org_config):
        if org_config.scratch and org_config.date_created and org_config.expired:
            click.echo(click.style("The scratch org is expired", fg="yellow"))
            if click.confirm("Attempt to recreate the scratch org?", default=True):
                self.keychain.create_scratch_org(
                    org_name, org_config.config_name, org_config.days
                )
                click.echo(
                    "Org config was refreshed, attempting to recreate scratch org"
                )
                org_config = self.keychain.get_org(org_name)
                org_config.create_org()
            else:
                raise click.ClickException(
                    "The target scratch org is expired.  You can use cci org remove {} "
                    "to remove the org and then recreate the config manually".format(
                        org_name
                    )
                )

        return org_config

    def check_org_overwrite(self, org_name):
        try:
            org = self.keychain.get_org(org_name)
            if org.scratch:
                if org.created:
                    raise click.ClickException(
                        "Scratch org has already been created. "
                        "Use `cci org scratch_delete {}`".format(org_name)
                    )
            else:
                raise click.ClickException(
                    "Org {} already exists.  Use `cci org remove` to delete it.".format(
                        org_name
                    )
                )
        except OrgNotFound:
            pass
        return True

    def check_cumulusci_version(self):
        if self.project_config:
            min_cci_version = self.project_config.minimum_cumulusci_version
            if min_cci_version:
                parsed_version = pkg_resources.parse_version(min_cci_version)
                if get_installed_version() < parsed_version:
                    raise click.UsageError(
                        "This project requires CumulusCI version {} or later. "
                        "Please upgrade using pip install -U cumulusci".format(
                            min_cci_version
                        )
                    )
Пример #18
0
 def _load_global_config(self):
     try:
         self.global_config = YamlGlobalConfig()
     except NotInProject as e:
         raise click.UsageError(e.message)
Пример #19
0
class CliConfig(object):
    def __init__(self):
        self.global_config = None
        self.project_config = None
        self.keychain = None

        self._load_global_config()
        self._load_project_config()
        self._load_keychain()
        self._add_repo_to_path()

    def _add_repo_to_path(self):
        if self.project_config:
            sys.path.append(self.project_config.repo_root)

    def _load_global_config(self):
        self.global_config = YamlGlobalConfig()

    def _load_project_config(self):
        try:
            self.project_config = self.global_config.get_project_config()
        except ProjectConfigNotFound:
            pass
        except NotInProject as e:
            raise click.UsageError(e.message)
        except ConfigError as e:
            raise click.UsageError("Config Error: {}".format(e.message))

    def _load_keychain(self):
        self.keychain_key = os.environ.get("CUMULUSCI_KEY")
        if self.project_config:
            keychain_class = os.environ.get(
                "CUMULUSCI_KEYCHAIN_CLASS",
                self.project_config.cumulusci__keychain)
            self.keychain_class = import_class(keychain_class)
            self.keychain = self.keychain_class(self.project_config,
                                                self.keychain_key)
            self.project_config.set_keychain(self.keychain)

    def get_org(self, org_name=None, fail_if_missing=True):
        if org_name:
            org_config = self.keychain.get_org(org_name)
        else:
            org_name, org_config = self.keychain.get_default_org()
        if org_config:
            org_config = self.check_org_expired(org_name, org_config)
        elif fail_if_missing:
            raise click.UsageError("No org specified and no default org set.")
        return org_name, org_config

    def check_org_expired(self, org_name, org_config):
        if org_config.scratch and org_config.date_created and org_config.expired:
            click.echo(click.style("The scratch org is expired", fg="yellow"))
            if click.confirm("Attempt to recreate the scratch org?",
                             default=True):
                self.keychain.create_scratch_org(org_name,
                                                 org_config.config_name,
                                                 org_config.days)
                click.echo(
                    "Org config was refreshed, attempting to recreate scratch org"
                )
                org_config = self.keychain.get_org(org_name)
                org_config.create_org()
            else:
                raise click.ClickException(
                    "The target scratch org is expired.  You can use cci org remove {} "
                    "to remove the org and then recreate the config manually".
                    format(org_name))

        return org_config

    def check_org_overwrite(self, org_name):
        try:
            org = self.keychain.get_org(org_name)
            if org.scratch:
                if org.created:
                    raise click.ClickException(
                        "Scratch org has already been created. "
                        "Use `cci org scratch_delete {}`".format(org_name))
            else:
                raise click.ClickException(
                    "Org {} already exists.  Use `cci org remove` to delete it."
                    .format(org_name))
        except OrgNotFound:
            pass
        return True

    def check_keychain(self):
        self.check_project_config()
        if self.keychain and self.keychain.encrypted and not self.keychain_key:
            raise click.UsageError(
                "You must set the environment variable CUMULUSCI_KEY "
                "with the encryption key to be used for storing org credentials"
            )

    def check_project_config(self):
        if not self.project_config:
            raise click.UsageError(
                'No project configuration found.  You can use the "project init" '
                "command to initilize the project for use with CumulusCI")
Пример #20
0
 def _load_global_config(self):
     self.global_config = YamlGlobalConfig()
Пример #21
0
 def test_load_project_config_not_repo(self, mock_class):
     mock_class.return_value = self.tempdir_home
     os.chdir(self.tempdir_project)
     global_config = YamlGlobalConfig()
     config = YamlProjectConfig(global_config)