Exemple #1
0
    def test_force_refresh_oauth_token_error(self, Command):
        Command.return_value = p = mock.Mock(
            stdout=io.BytesIO(b'error'),
            stderr=io.BytesIO(b''),
            returncode=1,
        )

        config = ScratchOrgConfig({'username': '******'}, 'test')
        with self.assertRaises(ScratchOrgException):
            config.force_refresh_oauth_token()
Exemple #2
0
    def test_scratch_info_non_json_response(self, Command):
        Command.return_value = mock.Mock(
            stderr=io.BytesIO(b''),
            stdout=io.BytesIO(b'<html></html>'),
            returncode=0,
        )

        config = ScratchOrgConfig({'username': '******'}, 'test')
        with self.assertRaises(ScratchOrgException):
            config.scratch_info
    def test_delete_org_error(self, Command):
        Command.return_value = mock.Mock(
            stdout=io.BytesIO(b"An error occurred deleting this org"),
            stderr=io.BytesIO(b""),
            returncode=1,
        )

        config = ScratchOrgConfig({"username": "******", "created": True}, "test")
        with self.assertRaises(ScratchOrgException):
            config.delete_org()
Exemple #4
0
    def test_create_org_command_error(self, Command):
        Command.return_value = mock.Mock(
            stdout=io.BytesIO(b''),
            stderr=io.BytesIO(b'error'),
            returncode=1,
        )

        config = ScratchOrgConfig({'config_file': 'tmp'}, 'test')
        with self.assertRaises(ScratchOrgException):
            config.create_org()
Exemple #5
0
    def test_delete_org_error(self, Command):
        Command.return_value = mock.Mock(
            stdout=io.BytesIO(b'An error occurred deleting this org'),
            stderr=io.BytesIO(b''),
            returncode=1,
        )

        config = ScratchOrgConfig({'username': '******', 'created': True}, 'test')
        with self.assertRaises(ScratchOrgException):
            config.delete_org()
Exemple #6
0
def org_import(config, username_or_alias, org_name):
    org_config = {"username": username_or_alias}
    scratch_org_config = ScratchOrgConfig(org_config, org_name)
    scratch_org_config.config["created"] = True
    config.keychain.set_org(scratch_org_config)
    click.echo(
        "Imported scratch org: {org_id}, username: {username}".format(
            **scratch_org_config.scratch_info
        )
    )
    def test_generate_password(self, Command):
        p = mock.Mock(stderr=io.BytesIO(b"error"),
                      stdout=io.BytesIO(b"out"),
                      returncode=0)
        Command.return_value = p

        config = ScratchOrgConfig({"username": "******"}, "test")
        config.generate_password()

        p.run.assert_called_once()
    def test_email_address_from_git(self, Command):
        config = ScratchOrgConfig({}, "test")
        Command.return_value = p = mock.Mock(
            stdout=io.BytesIO(b"*****@*****.**"),
            stderr=io.BytesIO(b""),
            returncode=0)

        self.assertEqual("*****@*****.**", config.email_address)
        config.email_address  # Make sure value is cached
        p.run.assert_called_once()
    def test_delete_org(self, Command):
        Command.return_value = mock.Mock(
            stdout=io.BytesIO(b"info"), stderr=io.BytesIO(b""), returncode=0
        )

        config = ScratchOrgConfig({"username": "******", "created": True}, "test")
        config.delete_org()

        self.assertFalse(config.config["created"])
        self.assertIs(config.config["username"], None)
Exemple #10
0
    def setUp(self):
        self.global_config = BaseGlobalConfig()
        self.project_config = BaseProjectConfig(self.global_config)
        self.project_config.config["services"] = {
            "connected_app": {
                "attributes": {
                    "test": {
                        "required": True
                    }
                }
            },
            "github": {
                "attributes": {
                    "git": {
                        "required": True
                    },
                    "password": {}
                }
            },
            "mrbelvedere": {
                "attributes": {
                    "mr": {
                        "required": True
                    }
                }
            },
            "not_configured": {
                "attributes": {
                    "foo": {
                        "required": True
                    }
                }
            },
        }
        self.project_config.project__name = "TestProject"
        self.project_name = "TestProject"
        self.org_config = OrgConfig({"foo": "bar"}, "test")
        self.scratch_org_config = ScratchOrgConfig(
            {
                "foo": "bar",
                "scratch": True
            }, "test_scratch")
        self.services = {
            "connected_app": ServiceConfig({"test": "value"}),
            "github": ServiceConfig({"git": "hub"}),
            "mrbelvedere": ServiceConfig({"mr": "belvedere"}),
        }
        self.key = "0123456789123456"

        self._mk_temp_home()
        self._expanduser_patch = mock.patch("os.path.expanduser",
                                            return_value=self.tempdir_home)
        self._expanduser_patch.__enter__()
        self._mk_temp_project()
        os.chdir(self.tempdir_project)
Exemple #11
0
 def _load_keychain_orgs(self):
     for key, value in os.environ.items():
         if key.startswith(self.org_var_prefix):
             org_config = json.loads(value)
             if org_config.get('scratch'):
                 self.orgs[
                     key[len(self.org_var_prefix):]] = ScratchOrgConfig(
                         json.loads(value))
             else:
                 self.orgs[key[len(self.org_var_prefix):]] = OrgConfig(
                     json.loads(value))
Exemple #12
0
 def _load_orgs(self):
     for key, value in self._get_env():
         if key.startswith(self.org_var_prefix):
             org_config = json.loads(value)
             org_name = key[len(self.org_var_prefix):]
             if org_config.get('scratch'):
                 self.orgs[org_name] = ScratchOrgConfig(
                     json.loads(value), org_name)
             else:
                 self.orgs[org_name] = OrgConfig(json.loads(value),
                                                 org_name)
    def test_user_id_from_org(self, Command):
        sf = mock.Mock()
        sf.query_all.return_value = {"records": [{"Id": "test"}]}

        config = ScratchOrgConfig({"username": "******"}, "test")
        config._sfdx_info = {
            "instance_url": "test_instance",
            "access_token": "token",
        }
        with mock.patch("cumulusci.core.config.OrgConfig.salesforce_client", sf):
            self.assertEqual(config.user_id, "test")
Exemple #14
0
    def test_force_refresh_oauth_token(self, Command):
        Command.return_value = p = mock.Mock(
            stdout=io.BytesIO(b''),
            stderr=io.BytesIO(b''),
            returncode=0,
        )

        config = ScratchOrgConfig({'username': '******'}, 'test')
        config.force_refresh_oauth_token()

        p.run.assert_called_once()
Exemple #15
0
    def test_generate_password(self, Command):
        p = mock.Mock(
            stderr=io.BytesIO(b'error'),
            stdout=io.BytesIO(b'out'),
            returncode=0,
        )
        Command.return_value = p

        config = ScratchOrgConfig({'username': '******'}, 'test')
        config.generate_password()

        p.run.assert_called_once()
    def test_get_access_token__unknown_user(self, Command):
        sf = mock.Mock()
        sf.query_all.return_value = {"records": []}

        config = ScratchOrgConfig({}, "test")

        with mock.patch("cumulusci.core.config.OrgConfig.salesforce_client", sf):
            with pytest.raises(
                SfdxOrgException,
                match="Couldn't find a username for the specified user",
            ):
                config.get_access_token(alias="dadvisor")
Exemple #17
0
    def test_generate_password_failed(self, Command):
        p = mock.Mock()
        p.stderr = io.BytesIO(b'error')
        p.stdout = io.BytesIO(b'out')
        p.returncode = 1
        Command.return_value = p

        config = ScratchOrgConfig({'username': '******'}, 'test')
        config.logger = mock.Mock()
        config.generate_password()

        config.logger.warn.assert_called_once()
Exemple #18
0
    def test_delete_org(self, Command):
        Command.return_value = mock.Mock(
            stdout=io.BytesIO(b'info'),
            stderr=io.BytesIO(b''),
            returncode=0,
        )

        config = ScratchOrgConfig({'username': '******', 'created': True}, 'test')
        config.delete_org()

        self.assertFalse(config.config['created'])
        self.assertIs(config.config['username'], None)
    def test_generate_password_failed(self, Command):
        p = mock.Mock()
        p.stderr = io.BytesIO(b"error")
        p.stdout = io.BytesIO(b"out")
        p.returncode = 1
        Command.return_value = p

        config = ScratchOrgConfig({"username": "******"}, "test")
        config.logger = mock.Mock()
        config.generate_password()

        config.logger.warning.assert_called_once()
    def test_scratch_info_command_error(self, Command):
        Command.return_value = mock.Mock(
            stderr=io.BytesIO(b"error"), stdout=io.BytesIO(b"out"), returncode=1
        )

        config = ScratchOrgConfig(
            {"username": "******", "email_address": "*****@*****.**", "created": True},
            "test",
        )

        with pytest.raises(SfdxOrgException, match="error"):
            config.scratch_info
Exemple #21
0
def org_import(config, username_or_alias, org_name):
    org_config = {"username": username_or_alias}
    scratch_org_config = ScratchOrgConfig(org_config, org_name)
    scratch_org_config.config["created"] = True

    info = scratch_org_config.scratch_info
    scratch_org_config.config["days"] = calculate_org_days(info)
    scratch_org_config.config["date_created"] = parse_api_datetime(
        info["created_date"])

    config.keychain.set_org(scratch_org_config)
    click.echo("Imported scratch org: {org_id}, username: {username}".format(
        **scratch_org_config.scratch_info))
    def test_scratch_info_command_error(self, Command):
        Command.return_value = mock.Mock(stderr=io.BytesIO(b"error"),
                                         stdout=io.BytesIO(b"out"),
                                         returncode=1)

        config = ScratchOrgConfig({"username": "******"}, "test")

        try:
            config.scratch_info
        except ScratchOrgException as err:
            self.assertEqual(str(err), "\nstderr:\nerror\nstdout:\nout")
        else:
            self.fail("Expected ScratchOrgException")
    def test_scratch_info_username_not_found(self, Command):
        Command.return_value = mock.Mock(
            stderr=io.BytesIO(b"error"), stdout=io.BytesIO(b"out"), returncode=0
        )

        config = ScratchOrgConfig(
            {"config_file": "tmp.json", "email_address": "*****@*****.**"}, "test"
        )

        with temporary_dir():
            with open("tmp.json", "w") as f:
                f.write("{}")
            with self.assertRaises(ScratchOrgException):
                config.scratch_info
Exemple #24
0
def org_scratch(config, config_name, org_name, delete):
    check_connected_app(config)
  
    scratch_configs = getattr(config.project_config, 'orgs__scratch')
    if not scratch_configs:
        raise click.UsageError( 'No scratch org configs found in cumulusci.yml')
    scratch_config = scratch_configs.get(config_name)
    if not scratch_config:
        raise click.UsageError(
            'No scratch org config named {} found in the cumulusci.yml file'.format(config_name)
        )

    org_config = ScratchOrgConfig(scratch_config) 
    config.keychain.set_org(org_name, org_config)
    def test_create_org_command_error(self, Command):
        Command.return_value = mock.Mock(
            stdout=io.BytesIO(b""), stderr=io.BytesIO(b"scratcherror"), returncode=1
        )

        config = ScratchOrgConfig(
            {"config_file": "tmp.json", "email_address": "*****@*****.**"}, "test"
        )
        with temporary_dir():
            with open("tmp.json", "w") as f:
                f.write("{}")

            with self.assertRaises(ScratchOrgException) as ctx:
                config.create_org()
                self.assertIn("scratcherror", str(ctx.error))
Exemple #26
0
    def test_scratch_info_command_error(self, Command):
        Command.return_value = mock.Mock(
            stderr=io.BytesIO(b'error'),
            stdout=io.BytesIO(b'out'),
            returncode=1,
        )

        config = ScratchOrgConfig({'username': '******'}, 'test')

        try:
            config.scratch_info
        except ScratchOrgException as err:
            self.assertEqual(str(err), '\nstderr:\nerror\nstdout:\nout')
        else:
            self.fail('Expected ScratchOrgException')
Exemple #27
0
    def setUp(self):
        self.universal_config = UniversalConfig()
        self.project_config = BaseProjectConfig(self.universal_config,
                                                config={"noyaml": True})
        self.project_config.config["services"] = {
            "connected_app": {
                "attributes": {
                    "test": {
                        "required": True
                    }
                }
            },
            "github": {
                "attributes": {
                    "git": {
                        "required": True
                    },
                    "password": {}
                }
            },
            "not_configured": {
                "attributes": {
                    "foo": {
                        "required": True
                    }
                }
            },
        }
        self.project_config.project__name = "TestProject"
        self.project_name = "TestProject"
        self.org_config = OrgConfig({"foo": "bar"}, "test")
        self.scratch_org_config = ScratchOrgConfig(
            {
                "foo": "bar",
                "scratch": True
            }, "test_scratch")
        self.services = {
            "connected_app": ServiceConfig({"test": "value"}),
            "github": ServiceConfig({"git": "hub"}),
        }
        self.key = "0123456789123456"

        self._mk_temp_home()
        self._home_patch = mock.patch("pathlib.Path.home",
                                      return_value=Path(self.tempdir_home))
        self._home_patch.__enter__()
        self._mk_temp_project()
        os.chdir(self.tempdir_project)
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(self.global_config)
     self.project_config.config['services'] = {
         'connected_app': {
             'attributes': {
                 'test': {
                     'required': True
                 }
             }
         },
         'github': {
             'attributes': {
                 'git': {
                     'required': True
                 },
                 'password': {}
             }
         },
         'mrbelvedere': {
             'attributes': {
                 'mr': {
                     'required': True
                 }
             }
         },
         'not_configured': {
             'attributes': {
                 'foo': {
                     'required': True
                 }
             }
         },
     }
     self.project_config.project__name = 'TestProject'
     self.project_name = 'TestProject'
     self.org_config = OrgConfig({'foo': 'bar'}, 'test')
     self.scratch_org_config = ScratchOrgConfig(
         {
             'foo': 'bar',
             'scratch': True
         }, 'test_scratch')
     self.services = {
         'connected_app': ServiceConfig({'test': 'value'}),
         'github': ServiceConfig({'git': 'hub'}),
         'mrbelvedere': ServiceConfig({'mr': 'belvedere'}),
     }
     self.key = '0123456789123456'
Exemple #29
0
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(self.global_config,
                                             config={"no_yaml": True})
     self.project_config.config["services"] = {
         "connected_app": {
             "attributes": {
                 "test": {
                     "required": True
                 }
             }
         },
         "github": {
             "attributes": {
                 "name": {
                     "required": True
                 },
                 "password": {}
             }
         },
         "mrbelvedere": {
             "attributes": {
                 "mr": {
                     "required": True
                 }
             }
         },
         "not_configured": {
             "attributes": {
                 "foo": {
                     "required": True
                 }
             }
         },
     }
     self.project_config.project__name = "TestProject"
     self.services = {
         "connected_app": ServiceConfig({"test": "value"}),
         "github": ServiceConfig({"name": "hub"}),
         "mrbelvedere": ServiceConfig({"mr": "belvedere"}),
     }
     self.org_config = OrgConfig({"foo": "bar"}, "test")
     self.scratch_org_config = ScratchOrgConfig(
         {
             "foo": "bar",
             "scratch": True
         }, "test_scratch")
     self.key = "0123456789123456"
    def test_scratch_info_password_from_config(self, Command):
        result = b"""{
    "result": {
        "instanceUrl": "url",
        "accessToken": "access!token",
        "username": "******"
    }
}"""
        Command.return_value = mock.Mock(
            stderr=io.BytesIO(b""), stdout=io.BytesIO(result), returncode=0
        )

        config = ScratchOrgConfig({"username": "******", "password": "******"}, "test")
        info = config.scratch_info

        self.assertEqual(info["password"], "password")