Пример #1
0
 def _test_get_default_org(self):
     keychain = self.keychain_class(self.project_config, self.key)
     org_config = self.org_config.config.copy()
     org_config = OrgConfig(org_config)
     org_config.config['default'] = True
     keychain.set_org('test', org_config)
     self.assertEquals(keychain.get_default_org()[1].config, org_config.config)
 def test_get_default_org(self):
     keychain = self.keychain_class(self.project_config, self.key)
     org_config = self.org_config.config.copy()
     org_config = OrgConfig(org_config, "test")
     org_config.config["default"] = True
     keychain.set_org(org_config)
     self.assertEqual(keychain.get_default_org()[1].config, org_config.config)
Пример #3
0
    def test_refresh_oauth_token_error(self, SalesforceOAuth2):
        config = OrgConfig({"refresh_token": mock.sentinel.refresh_token}, "test")
        keychain = mock.Mock()
        SalesforceOAuth2.return_value = oauth = mock.Mock()
        oauth.refresh_token.return_value = mock.Mock(status_code=400, text=":(")

        with self.assertRaises(SalesforceCredentialsException):
            config.refresh_oauth_token(keychain)
Пример #4
0
 def _test_unset_default_org(self):
     keychain = self.keychain_class(self.project_config, self.key)
     org_config = self.org_config.config.copy()
     org_config = OrgConfig(org_config)
     org_config.config["default"] = True
     keychain.set_org("test", org_config)
     keychain.unset_default_org()
     self.assertEquals(keychain.get_default_org(), None)
Пример #5
0
    def test_refresh_oauth_token(self, SalesforceOAuth2):
        config = OrgConfig({"refresh_token": mock.sentinel.refresh_token}, "test")
        config._load_userinfo = mock.Mock()
        config._load_orginfo = mock.Mock()
        keychain = mock.Mock()
        SalesforceOAuth2.return_value = oauth = mock.Mock()
        oauth.refresh_token.return_value = resp = mock.Mock(status_code=200)
        resp.json.return_value = {}

        config.refresh_oauth_token(keychain)

        oauth.refresh_token.assert_called_once_with(mock.sentinel.refresh_token)
Пример #6
0
def org_connect(config, org_name, sandbox, login_url, global_org):
    check_connected_app(config)

    connected_app = config.keychain.get_connected_app()
    if sandbox:
        login_url = 'https://test.salesforce.com'

    oauth_capture = CaptureSalesforceOAuth(
        client_id=connected_app.client_id,
        client_secret=connected_app.client_secret,
        callback_url=connected_app.callback_url,
        auth_site=login_url,
        scope='web full refresh_token')
    oauth_dict = oauth_capture()
    org_config = OrgConfig(oauth_dict)
    org_config.load_userinfo()

    config.keychain.set_org(org_name, org_config, global_org)
Пример #7
0
 def test_unset_default_org__with_files(self, Command):
     keychain = self.keychain_class(self.project_config, self.key)
     org_config = self.org_config.config.copy()
     org_config = OrgConfig(org_config, "test")
     keychain.set_org(org_config)
     keychain.set_default_org("test")
     keychain.unset_default_org()
     self.assertEqual(keychain.get_default_org()[1], None)
     assert not self._default_org_path().exists()
Пример #8
0
    def setUp(self):
        self.project_config = create_project_config('TestOwner', 'TestRepo')
        self.project_config.config['tasks'] = {
            'pass_name': {
                'description': 'Pass the name',
                'class_path':
                'cumulusci.core.tests.test_flows._TaskReturnsStuff',
            },
            'name_response': {
                'description': 'Pass the name',
                'class_path':
                'cumulusci.core.tests.test_flows._TaskResponseName',
            },
            'raise_exception': {
                'description': 'Raises an exception',
                'class_path':
                'cumulusci.core.tests.test_flows._TaskRaisesException',
                'options': {
                    'exception': Exception,
                    'message': 'Test raised exception as expected',
                }
            },
            'sfdc_task': {
                'description': 'An sfdc task',
                'class_path': 'cumulusci.core.tests.test_flows._SfdcTask'
            },
        }
        self.project_config.config['flows'] = {
            'nested_flow': {
                'description': 'A flow that runs inside another flow',
                'tasks': {
                    1: {
                        'task': 'pass_name'
                    },
                },
            },
            'nested_flow_2': {
                'description':
                'A flow that runs inside another flow, and calls another flow',
                'tasks': {
                    1: {
                        'task': 'pass_name'
                    },
                    2: {
                        'flow': 'nested_flow'
                    },
                },
            },
        }
        self.org_config = OrgConfig(
            {
                'username': '******',
                'org_id': ORG_ID
            }, 'test')

        self._flow_log_handler.reset()
        self.flow_log = self._flow_log_handler.messages
Пример #9
0
    def test_get_org(self):
        config = CliRuntime()
        config.keychain = mock.Mock()
        config.keychain.get_org.return_value = org_config = OrgConfig({},
                                                                      "test")

        org_name, org_config_result = config.get_org("test")
        self.assertEqual("test", org_name)
        self.assertIs(org_config, org_config_result)
Пример #10
0
 def test_load_scratch_orgs_existing_org(self):
     self.project_config.config["orgs"] = {}
     self.project_config.config["orgs"]["scratch"] = {}
     self.project_config.config["orgs"]["scratch"]["test"] = {}
     keychain = self.keychain_class(self.project_config, self.key)
     keychain.set_org(OrgConfig({}, "test"))
     self.assertEqual(list(keychain.orgs), ["test"])
     org = keychain.get_org("test")
     self.assertEqual(org.scratch, None)
Пример #11
0
 def test_start_url(self):
     config = OrgConfig(
         {"instance_url": "https://na01.salesforce.com", "access_token": "TOKEN"},
         "test",
     )
     self.assertEqual(
         "https://na01.salesforce.com/secur/frontdoor.jsp?sid=TOKEN",
         config.start_url,
     )
Пример #12
0
    def test_get_community_info__fetch_if_not_in_cache(self):
        """Verify that the internal cache is automatically refreshed

        The cache should be refreshed automatically if the requested community
        is not in the cache.
        """
        responses.add(
            "GET",
            "https://test/services/data/v45.0/connect/communities",
            json={"communities": [{"name": "Kōkua"}]},
        )

        config = OrgConfig(
            {"instance_url": "https://test", "access_token": "TOKEN"}, "test"
        )
        config._community_info_cache = {}
        info = config.get_community_info("Kōkua")
        self.assertEqual(info["name"], "Kōkua")
Пример #13
0
 def test_sf_instance(self):
     org_config = OrgConfig(
         {
             "instance_url": "https://foo/",
             "access_token": "TOKEN"
         }, "test")
     task = create_task(BaseSalesforceApiTask, org_config=org_config)
     task._init_task()
     self.assertFalse(task.sf.sf_instance.endswith("/"))
Пример #14
0
    def setUp(self):
        self.project_config = create_project_config("TestOwner", "TestRepo")
        self.project_config.config["tasks"] = {
            "pass_name": {
                "description": "Pass the name",
                "class_path":
                "cumulusci.core.tests.test_flows._TaskReturnsStuff",
            },
            "name_response": {
                "description": "Pass the name",
                "class_path":
                "cumulusci.core.tests.test_flows._TaskResponseName",
            },
            "raise_exception": {
                "description": "Raises an exception",
                "class_path":
                "cumulusci.core.tests.test_flows._TaskRaisesException",
                "options": {
                    "exception": Exception,
                    "message": "Test raised exception as expected",
                },
            },
            "sfdc_task": {
                "description": "An sfdc task",
                "class_path": "cumulusci.core.tests.test_flows._SfdcTask",
            },
        }
        self.project_config.config["flows"] = {
            "nested_flow": {
                "description": "A flow that runs inside another flow",
                "steps": {
                    1: {
                        "task": "pass_name"
                    }
                },
            },
            "nested_flow_2": {
                "description":
                "A flow that runs inside another flow, and calls another flow",
                "steps": {
                    1: {
                        "task": "pass_name"
                    },
                    2: {
                        "flow": "nested_flow"
                    }
                },
            },
        }
        self.org_config = OrgConfig(
            {
                "username": "******",
                "org_id": ORG_ID
            }, "test")

        self._flow_log_handler.reset()
        self.flow_log = self._flow_log_handler.messages
Пример #15
0
 def test_delete_org__keep_org(self):
     build = BuildFactory(keep_org=True)
     org = ScratchOrgInstanceFactory()
     org.delete_org = mock.Mock()
     build.org_instance = org
     org_config = OrgConfig({"scratch": True}, "dev")
     build.delete_org(org_config)
     org.delete_org.assert_not_called()
     detach_logger(build)
Пример #16
0
 def _test_load_scratch_orgs_existing_org(self):
     self.project_config.config['orgs'] = {}
     self.project_config.config['orgs']['scratch'] = {}
     self.project_config.config['orgs']['scratch']['test'] = {}
     keychain = self.keychain_class(self.project_config, self.key)
     keychain.set_org(OrgConfig({}, 'test'))
     self.assertEquals(list(keychain.orgs), ['test'])
     org = keychain.get_org('test')
     self.assertEquals(org.scratch, None)
Пример #17
0
    def setUp(self):
        self.global_config = BaseGlobalConfig()
        self.project_config = BaseProjectConfig(self.global_config,
                                                config={"noyaml": True})
        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)
Пример #18
0
    def test_load_orginfo(self):
        config = OrgConfig(
            {
                "instance_url": "https://example.com",
                "access_token": "TOKEN",
                "id": "OODxxxxxxxxxxxx/user",
            },
            "test",
        )
        responses.add(
            "GET",
            "https://example.com/services/data/v45.0/sobjects/Organization/OODxxxxxxxxxxxx",
            json={"OrganizationType": "Enterprise Edition", "IsSandbox": False},
        )

        config._load_orginfo()

        self.assertEqual("Enterprise Edition", config.org_type)
        self.assertEqual(False, config.is_sandbox)
Пример #19
0
    def setUp(self):
        self.project_config = create_project_config("TestOwner", "TestRepo")
        self.org_config = OrgConfig(
            {"username": "******", "org_id": ORG_ID}, "test"
        )
        self.org_config.refresh_oauth_token = mock.Mock()

        self._flow_log_handler.reset()
        self.flow_log = self._flow_log_handler.messages
        self._setup_project_config()
Пример #20
0
    def test_set_default_org(self, Command):
        keychain = self.keychain_class(self.project_config, self.key)
        org_config = self.org_config.config.copy()
        org_config = OrgConfig(org_config, "test")
        keychain.set_org(org_config)
        keychain.set_default_org("test")
        expected_org_config = org_config.config.copy()
        expected_org_config["default"] = True

        self.assertEqual(expected_org_config, keychain.get_default_org()[1].config)
Пример #21
0
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(self.global_config)
     self.org_config = OrgConfig({
         'username': USERNAME,
         'org_id': ORG_ID
     }, 'test')
     self.task_config = TaskConfig()
     self._task_log_handler.reset()
     self.task_log = self._task_log_handler.messages
Пример #22
0
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(self.global_config)
     self.org_config = OrgConfig({
         "username": USERNAME,
         "org_id": ORG_ID
     }, "test")
     self.task_config = TaskConfig()
     self._task_log_handler.reset()
     self.task_log = self._task_log_handler.messages
Пример #23
0
    def test_check_org_overwrite_scratch_exists(self):
        config = CliConfig()
        config.keychain.get_org = mock.Mock(
            return_value=OrgConfig({
                "scratch": True,
                "created": True
            }, "test"))

        with self.assertRaises(click.ClickException):
            config.check_org_overwrite("test")
Пример #24
0
    def test_load_orginfo(self):
        config = OrgConfig(
            {
                "instance_url": "https://example.com",
                "access_token": "TOKEN",
                "id": "OODxxxxxxxxxxxx/user",
            },
            "test",
        )
        responses.add(
            "GET",
            "https://example.com/services/data/v45.0/sobjects/Organization/OODxxxxxxxxxxxx",
            json={"OrganizationType": "Enterprise Edition", "IsSandbox": False},
        )

        config._load_orginfo()

        self.assertEqual("Enterprise Edition", config.org_type)
        self.assertEqual(False, config.is_sandbox)
Пример #25
0
def refresh_access_token(*, config, org_name, scratch_org,
                         originating_user_id):
    """
    Construct a new OrgConfig because ScratchOrgConfig tries to use sfdx
    which we don't want now -- this is a total hack which I'll try to
    smooth over with some improvements in CumulusCI
    """
    try:
        org_config = OrgConfig(config, org_name)
        org_config.refresh_oauth_token = Mock()
        info = jwt_session(SF_CLIENT_ID, SF_CLIENT_KEY, org_config.username,
                           org_config.instance_url)
        org_config.config["access_token"] = info["access_token"]
        return org_config
    except HTTPError as err:
        if get_current_job():
            job_id = get_current_job().id
            # This error is user-facing, and so for makemessages to
            # pick it up correctly, we need it to be a single,
            # unbroken, string literal (even though adjacent string
            # literals should be parsed by the AST into a single
            # string literal and picked up by makemessages, but
            # that's a gripe for another day). We have relatively
            # few errors that propagate directly from the backend
            # like this, but when we do, this is the pattern we
            # should use.
            #
            # This is also why we repeat the first sentence.
            error_msg = _(
                f"Are you certain that the org still exists? If you need support, your job ID is {job_id}."  # noqa: B950
            )
        else:
            error_msg = _(
                f"Are you certain that the org still exists? {err.args[0]}")

        err = err.__class__(
            error_msg,
            *err.args[1:],
        )
        scratch_org.remove_scratch_org(err,
                                       originating_user_id=originating_user_id)
        raise err
 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):].lower()
             if org_config.get("scratch"):
                 self.orgs[org_name] = scratch_org_factory(
                     json.loads(value), org_name)
             else:
                 self.orgs[org_name] = OrgConfig(json.loads(value),
                                                 org_name)
Пример #27
0
 def setUp(self):
     self.universal_config = UniversalConfig()
     self.project_config = BaseProjectConfig(self.universal_config,
                                             config={"noyaml": True})
     self.org_config = OrgConfig({
         "username": USERNAME,
         "org_id": ORG_ID
     }, "test")
     self.task_config = TaskConfig()
     self._task_log_handler.reset()
     self.task_log = self._task_log_handler.messages
    def test_update_dependency_latest_option_err(self):
        project_config = create_project_config()
        project_config.config["project"]["dependencies"] = [{
            "namespace": "foo"
        }]
        task = create_task(UpdateDependencies, project_config=project_config)
        task.options["include_beta"] = True
        task.org_config = OrgConfig(None, None)

        with self.assertRaises(TaskOptionsError):
            task()
Пример #29
0
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(self.global_config)
     self.connected_app_config = ConnectedAppOAuthConfig({'test': 'value'})
     self.services = {
         'github': ServiceConfig({'git': 'hub'}),
         'mrbelvedere': ServiceConfig({'mr': 'belvedere'}),
         'apextestsdb': ServiceConfig({'apex': 'testsdb'}),
     }
     self.org_config = OrgConfig({'foo': 'bar'})
     self.key = '0123456789123456'
Пример #30
0
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(
         self.global_config, config={"noyaml": True}
     )
     self.task_config = TaskConfig({"options": {"command": "ls"}})
     self.org_config = OrgConfig(
         {"access_token": "TOKEN", "instance_url": "https://na01.salesforce.com"},
         "test",
     )
     self.org_config.refresh_oauth_token = mock.Mock()
Пример #31
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))
Пример #32
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)
Пример #33
0
    def test_org_list(self, echo):
        config = mock.Mock()
        config.project_config.keychain.list_orgs.return_value = [
            "test1", "test2"
        ]
        config.project_config.keychain.get_org.side_effect = [
            OrgConfig(
                {
                    "default": True,
                    "scratch": True,
                    "days_alive": 1,
                    "days": 7,
                    "expired": False,
                    "config_name": "dev",
                    "username": "******",
                },
                "test1",
            ),
            OrgConfig(
                {
                    "default": False,
                    "scratch": False,
                    "expired": False,
                    "config_name": "dev",
                    "username": "******",
                },
                "test2",
            ),
        ]

        run_click_command(cci.org_list, config=config)

        table = echo.call_args[0][0]
        self.assertEqual(
            """org    default  scratch  days    expired  config_name  username
-----  -------  -------  ------  -------  -----------  -----------------
test1  *        *        1 of 7           dev          [email protected]
test2                                     dev          [email protected]""",
            str(table),
        )
Пример #34
0
    def _test_set_default_org(self):
        keychain = self.keychain_class(self.project_config, self.key)
        org_config = self.org_config.config.copy()
        org_config = OrgConfig(org_config, 'test')
        keychain.set_org(org_config)
        keychain.set_default_org('test')
        expected_org_config = org_config.config.copy()
        expected_org_config['default'] = True

        self.assertEquals(
            expected_org_config,
            keychain.get_default_org()[1].config,
        )
Пример #35
0
def create_task(task_class, options=None, project_config=None, org_config=None):
    if project_config is None:
        project_config = create_project_config("TestRepo", "TestOwner")
    if org_config is None:
        org_config = OrgConfig(
            {
                "instance_url": "https://test.salesforce.com",
                "access_token": "TOKEN",
                "org_id": "ORG_ID",
                "username": "******",
            },
            "test",
        )
        org_config.refresh_oauth_token = mock.Mock()
    if options is None:
        options = {}
    task_config = TaskConfig({"options": options})
    with mock.patch(
        "cumulusci.tasks.salesforce.BaseSalesforceTask._get_client_name",
        return_value="ccitests",
    ):
        return task_class(project_config, task_config, org_config)
Пример #36
0
def org_connect(config, org_name, sandbox, login_url, default, global_org):
    check_connected_app(config)
    check_org_overwrite(config, org_name)

    connected_app = config.keychain.get_connected_app()
    if sandbox:
        login_url = 'https://test.salesforce.com'

    oauth_capture = CaptureSalesforceOAuth(
        client_id=connected_app.client_id,
        client_secret=connected_app.client_secret,
        callback_url=connected_app.callback_url,
        auth_site=login_url,
        scope='web full refresh_token')
    oauth_dict = oauth_capture()
    org_config = OrgConfig(oauth_dict, org_name)
    org_config.load_userinfo()

    config.keychain.set_org(org_config, global_org)

    if default:
        org = config.keychain.set_default_org(org_name)
        click.echo('{} is now the default org'.format(org_name))
Пример #37
0
    def test_check_org_expired(self):
        config = CliRuntime()
        config.keychain = mock.Mock()
        org_config = OrgConfig(
            {
                "scratch": True,
                "date_created": date.today() - timedelta(days=2),
                "expired": True,
            },
            "test",
        )

        config.check_org_expired("test", org_config)
        config.keychain.create_scratch_org.assert_called_once()
Пример #38
0
 def test_refresh_oauth_token_no_connected_app(self):
     config = OrgConfig({}, "test")
     with self.assertRaises(AttributeError):
         config.refresh_oauth_token(None)
Пример #39
0
 def test_can_delete(self):
     config = OrgConfig({}, "test")
     self.assertFalse(config.can_delete())