Ejemplo n.º 1
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: 45.0\n"

        os.chdir(self.tempdir_project)
        global_config = BaseGlobalConfig()
        config = BaseProjectConfig(global_config, additional_yaml=content)
        self.assertNotEqual(config.config_additional_yaml, {})
        self.assertEqual(config.project__package__api_version, 45.0)
Ejemplo n.º 2
0
 def test_run_task(self):
     with temporary_dir() as revert_path:
         with open(os.path.join(revert_path, "file"), "w"):
             pass
         path = os.path.join(os.path.dirname(revert_path),
                             os.path.basename(revert_path) + "_orig")
         project_config = BaseProjectConfig(BaseGlobalConfig(),
                                            config={"noyaml": True})
         task_config = TaskConfig(
             {"options": {
                 "path": path,
                 "revert_path": revert_path
             }})
         task = RevertUnmanagedEESrc(project_config, task_config)
         task()
         self.assertTrue(os.path.exists(os.path.join(path, "file")))
Ejemplo n.º 3
0
    def test_split_repo_url(self):
        name = "Cumulusci"
        owner = "SFDO-Tooling"
        project_config = BaseProjectConfig(BaseGlobalConfig())

        https_url = f"https://github.com/{owner}/{name}.git"
        info = project_config._split_repo_url(https_url)
        assert info["name"] == name
        assert info["owner"] == owner
        assert info["url"] == https_url

        ssh_url = f"[email protected]:{owner}/{name}.git"
        info = project_config._split_repo_url(ssh_url)
        assert info["name"] == name
        assert info["owner"] == owner
        assert info["url"] == ssh_url
Ejemplo n.º 4
0
 def test_pretty_dependencies(self):
     dep = {
         "namespace": "npsp",
         "version": "3",
         "boolean": False,
         "dependencies": [{
             "repo_name": "TestRepo",
             "dependencies": []
         }],
     }
     config = BaseProjectConfig(BaseGlobalConfig())
     result = "\n".join(config.pretty_dependencies([dep]))
     self.assertEqual(
         """  - dependencies: \n    \n      - repo_name: TestRepo\n    namespace: npsp\n    version: 3""",
         result,
     )
Ejemplo n.º 5
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": {
                 "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"
Ejemplo n.º 6
0
    def _run_task(self):
        # Find or create Version
        if not self.dry_run:
            product = self._find_product()
            version = self._find_or_create_version(product)

        # Check out the specified tag
        repo_owner = self.project_config.repo_owner
        repo_name = self.project_config.repo_name
        gh = self.project_config.get_github_api()
        repo = gh.repository(repo_owner, repo_name)
        tag = self.options["tag"]
        commit_sha = repo.tag(repo.ref("tags/" + tag).object.sha).object.sha
        self.logger.info(
            "Downloading commit {} of {} from GitHub".format(commit_sha, repo.full_name)
        )
        zf = download_extract_github(gh, repo_owner, repo_name, ref=commit_sha)
        with temporary_dir() as project_dir:
            zf.extractall(project_dir)
            project_config = BaseProjectConfig(
                self.project_config.global_config_obj,
                repo_info={
                    "root": project_dir,
                    "owner": repo_owner,
                    "name": repo_name,
                    "url": self.project_config.repo_url,
                    "branch": tag,
                    "commit": commit_sha,
                },
            )
            project_config.set_keychain(self.project_config.keychain)

            # Create each plan
            for plan_name, plan_config in self.plan_configs.items():
                steps = self._freeze_steps(project_config, plan_config)
                self.logger.debug("Prepared steps:\n" + json.dumps(steps, indent=4))
                if not self.dry_run:
                    self._publish_plan(product, version, plan_name, plan_config, steps)

            # Update version to set is_listed=True
            if not self.dry_run:
                self._call_api(
                    "PATCH",
                    "/versions/{}".format(version["id"]),
                    json={"is_listed": True},
                )
                self.logger.info("Published Version {}".format(version["url"]))
Ejemplo n.º 7
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': {
                 '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'
Ejemplo n.º 8
0
 def test_get_package_zip(self):
     project_config = BaseProjectConfig(
         UniversalConfig(),
         {
             "project": {
                 "package": {
                     "name": "TestPackage",
                     "api_version": "43.0"
                 }
             }
         },
     )
     task = create_task(CreatePackage, project_config=project_config)
     package_zip = task._get_package_zip()
     zf = zipfile.ZipFile(io.BytesIO(base64.b64decode(package_zip)), "r")
     package_xml = zf.read("package.xml")
     assert b"<fullName>TestPackage</fullName>" in package_xml
Ejemplo n.º 9
0
 def setUp(self):
     self.repo_api_url = "https://api.github.com/repos/TestOwner/TestRepo"
     universal_config = UniversalConfig()
     self.project_config = BaseProjectConfig(universal_config)
     self.project_config.set_keychain(BaseProjectKeychain(self.project_config, None))
     self.repo_root = TemporaryDirectory()
     self.project_config.repo_info["root"] = pathlib.Path(self.repo_root.name)
     self.project_config.keychain.set_service(
         "github",
         ServiceConfig(
             {
                 "username": "******",
                 "password": "******",
                 "email": "*****@*****.**",
             }
         ),
     )
Ejemplo n.º 10
0
    def test_process_github_dependency(self):
        global_config = BaseGlobalConfig()
        config = BaseProjectConfig(global_config)
        config.get_github_api = DummyGithub
        config.keychain = DummyKeychain()

        result = config.process_github_dependency(
            {
                "github": "https://github.com/SFDO-Tooling/CumulusCI-Test.git",
                "unmanaged": True,
                "skip": ["unpackaged/pre/skip", "unpackaged/post/skip"],
            }
        )
        self.assertEqual(
            result,
            [
                {
                    u"repo": CUMULUSCI_TEST_REPO,
                    u"ref": None,
                    u"subfolder": u"unpackaged/pre/pre",
                    u"unmanaged": True,
                    u"namespace_inject": None,
                    u"namespace_strip": None,
                    u"namespace_tokenize": None,
                },
                {u"version": "2", u"namespace": "ccitestdep"},
                {
                    u"repo": CUMULUSCI_TEST_REPO,
                    u"ref": None,
                    u"subfolder": u"src",
                    u"unmanaged": True,
                    u"namespace_inject": None,
                    u"namespace_strip": None,
                    u"namespace_tokenize": None,
                },
                {
                    u"repo": CUMULUSCI_TEST_REPO,
                    u"ref": None,
                    u"subfolder": u"unpackaged/post/post",
                    u"unmanaged": True,
                    u"namespace_inject": "ccitest",
                    u"namespace_strip": None,
                    u"namespace_tokenize": None,
                },
            ],
        )
Ejemplo n.º 11
0
    def test_task_run_not_found(self):
        config = mock.Mock()
        config.get_org.return_value = (None, None)
        config.project_config = BaseProjectConfig(BaseGlobalConfig(), config={})

        with self.assertRaises(click.UsageError):
            run_click_command(
                cci.task_run,
                config=config,
                task_name="test",
                org=None,
                o=[("color", "blue")],
                debug=False,
                debug_before=False,
                debug_after=False,
                no_prompt=True,
            )
Ejemplo n.º 12
0
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(self.global_config)
     self.project_config.config['services'] = {
         'github':{'attributes':{'name':{'required':True}, 'password':{}}},
         'mrbelvedere':{'attributes':{'mr':{'required':True}}},
         'apextestsdb':{'attributes':{'apex':{'required':True}}},
     }
     self.project_config.project__name = 'TestProject'
     self.connected_app_config = ConnectedAppOAuthConfig({'test': 'value'})
     self.services = {
         'github': ServiceConfig({'name': 'hub'}),
         'mrbelvedere': ServiceConfig({'mr': 'belvedere'}),
         'apextestsdb': ServiceConfig({'apex': 'testsdb'}),
     }
     self.org_config = OrgConfig({'foo': 'bar'})
     self.key = '0123456789123456'
Ejemplo n.º 13
0
 def setUp(self):
     self.api_version = 36.0
     self.global_config = BaseGlobalConfig(
         {'project': {'package': {'api_version': self.api_version}}})
     self.project_config = BaseProjectConfig(self.global_config)
     self.project_config.config['project'] = {
         'package': {
             'api_version': self.api_version,
         }
     }
     self.task_config = TaskConfig()
     self.org_config = OrgConfig({
         'instance_url': 'example.com',
         'access_token': 'abc123',
     })
     self.base_tooling_url = 'https://{}/services/data/v{}/tooling/'.format(
         self.org_config.instance_url, self.api_version)
Ejemplo n.º 14
0
 def test_run_task(self, removeXmlElement):
     with temporary_dir() as path:
         revert_path = os.path.join(os.path.dirname(path),
                                    os.path.basename(path) + "_revert")
         project_config = BaseProjectConfig(BaseGlobalConfig(),
                                            config={"noyaml": True})
         task_config = TaskConfig(
             {"options": {
                 "path": path,
                 "revert_path": revert_path
             }})
         task = CreateUnmanagedEESrc(project_config, task_config)
         task()
         removeXmlElement.assert_has_calls([
             mock.call("availableFields", path, "*.object"),
             mock.call("visibility[.='Protected']", path, "*.object"),
         ])
Ejemplo n.º 15
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: 45.0\n"
        self._create_project_config_local(content)

        with cd(self.tempdir_project):
            universal_config = UniversalConfig()
            config = BaseProjectConfig(universal_config)
            self.assertNotEqual(config.config_project_local, {})
            self.assertEqual(config.project__package__api_version, 45.0)
Ejemplo n.º 16
0
def project_config(repo_root):
    project_config = BaseProjectConfig(UniversalConfig(),
                                       repo_info={
                                           "root": repo_root,
                                           "branch": "main"
                                       })

    project_config.keychain = BaseProjectKeychain(project_config, key=None)
    pathlib.Path(repo_root, "orgs").mkdir()
    pathlib.Path(repo_root, "orgs", "scratch_def.json").write_text(
        json.dumps({
            "edition": "Developer",
            "settings": {},
        }))

    project_config.get_github_api = mock.Mock()

    return project_config
Ejemplo n.º 17
0
 def test_pretty_dependencies(self):
     repo = mock.Mock(full_name="TestRepo")
     dep = {
         "namespace": "npsp",
         "version": "3",
         "boolean": False,
         "dependencies": [{"repo": repo, "dependencies": []}],
     }
     config = BaseProjectConfig(BaseGlobalConfig())
     result = "\n".join(config.pretty_dependencies([dep]))
     self.assertEqual(
         """  - dependencies: 
 
   - repo: TestRepo
 namespace: npsp
 version: 3""",
         result,
     )
Ejemplo n.º 18
0
 def test_get_latest_tag_matching_prefix(self):
     config = BaseProjectConfig(
         BaseGlobalConfig(),
         {
             "project": {
                 "git": {
                     "prefix_beta": "beta/",
                     "prefix_release": "rel/"
                 }
             }
         },
     )
     github = self._make_github()
     github.repositories["CumulusCI"]._releases.append(
         DummyRelease("rel/0.9", "0.9"))
     config.get_github_api = mock.Mock(return_value=github)
     result = config.get_latest_tag()
     self.assertEqual("rel/0.9", result)
Ejemplo n.º 19
0
 def test_run_task(self):
     with temporary_dir() as path:
         os.mkdir(os.path.join(path, "classes"))
         class_path = os.path.join(path, "classes", "test.cls")
         with open(class_path, "w") as f:
             f.write("//cumulusci-managed")
         revert_path = os.path.join(os.path.dirname(path),
                                    os.path.basename(path) + "_revert")
         project_config = BaseProjectConfig(BaseGlobalConfig())
         task_config = TaskConfig(
             {"options": {
                 "path": path,
                 "revert_path": revert_path
             }})
         task = CreateManagedSrc(project_config, task_config)
         task()
         with open(class_path, "r") as f:
             result = f.read()
         self.assertEqual("", result)
Ejemplo n.º 20
0
    def test_sources(self, mock_add_path, mock_robot_run):
        """Verify that sources get added to PYTHONPATH when task runs"""
        universal_config = UniversalConfig()
        project_config = BaseProjectConfig(
            universal_config,
            {
                "sources": {
                    "test1": {
                        "path": "dummy1"
                    },
                    "test2": {
                        "path": "dummy2"
                    },
                }
            },
        )
        # get_namespace returns a config. The only part of the config
        # that the code uses is the repo_root property, so we don't need
        # a full blown config.
        project_config.get_namespace = mock.Mock(
            side_effect=lambda source: mock.Mock(repo_root=project_config.
                                                 sources[source]["path"]))

        task = create_task(
            Robot,
            {
                "suites": "test",
                "sources": ["test1", "test2"]
            },
            project_config=project_config,
        )

        mock_robot_run.return_value = 0
        self.assertNotIn("dummy1", sys.path)
        self.assertNotIn("dummy2", sys.path)
        task()
        project_config.get_namespace.assert_has_calls(
            [mock.call("test1"), mock.call("test2")])
        mock_add_path.assert_has_calls(
            [mock.call("dummy1", end=True),
             mock.call("dummy2", end=True)])
        self.assertNotIn("dummy1", sys.path)
        self.assertNotIn("dummy2", sys.path)
Ejemplo n.º 21
0
    def test_process_github_dependency_with_tag(self):
        global_config = BaseGlobalConfig()
        config = BaseProjectConfig(global_config)
        config.get_github_api = DummyGithub
        config.keychain = DummyKeychain()

        result = config.process_github_dependency(
            {
                "github": "https://github.com/SFDO-Tooling/CumulusCI-Test.git",
                "tag": "release/1.0",
            }
        )
        self.assertIn(
            {
                "namespace": "ccitest",
                "version": "1.0",
                "dependencies": [{"namespace": "ccitestdep", "version": "2"}],
            },
            result,
        )
Ejemplo n.º 22
0
    def test_repo_root_in_sys_path(self, mock_add_path, mock_robot_run):
        """Verify that the repo root is added to sys.path

        Normally, the repo root is added to sys.path in the __init__
        of BaseSalesforceTask. However, if we're running a task from
        another repo, the git root of that other repo isn't added. The
        robot task will do that; this verifies that.

        """
        mock_robot_run.return_value = 0
        universal_config = UniversalConfig()
        project_config = BaseProjectConfig(universal_config)
        with temporary_dir() as d:
            project_config.repo_info["root"] = d
            task = create_task(Robot, {"suites": "tests"},
                               project_config=project_config)
            self.assertNotIn(d, sys.path)
            task()
            mock_add_path.assert_called_once_with(d)
            self.assertNotIn(d, sys.path)
Ejemplo n.º 23
0
    def setUp(self):
        self.universal_config = UniversalConfig()
        self.project_config = BaseProjectConfig(self.universal_config,
                                                config={"noyaml": True})

        keychain = BaseProjectKeychain(self.project_config, "")
        self.project_config.set_keychain(keychain)

        self._task_log_handler.reset()
        self.task_log = self._task_log_handler.messages
        self.label = "Test_Label"
        self.username = "******"
        self.email = "TestUser@Email"
        self.task_config = TaskConfig({
            "options": {
                "label": self.label,
                "username": self.username,
                "email": self.email,
            }
        })
Ejemplo n.º 24
0
    def test_process_github_dependency(self):
        global_config = BaseGlobalConfig()
        config = BaseProjectConfig(global_config)
        config.get_github_api = DummyGithub
        config.keychain = DummyKeychain()

        result = config.process_github_dependency({
            'github': 'https://github.com/SalesforceFoundation/CumulusCI-Test',
            'unmanaged': True,
        })
        self.assertEqual(result, [
            {
                u'headers': {u'Authorization': u'token password'},
                u'namespace_inject': None,
                u'namespace_strip': None,
                u'namespace_tokenize': None,
                u'subfolder': u'CumulusCI-Test-master/unpackaged/pre/pre',
                u'unmanaged': True,
                u'zip_url': u'https://github.com/SalesforceFoundation/CumulusCI-Test/archive/master.zip',
            },
            {u'version': '2', u'namespace': 'ccitestdep'},
            {
                u'headers': {u'Authorization': u'token password'},
                u'namespace_inject': None,
                u'namespace_strip': None,
                u'namespace_tokenize': None,
                u'subfolder': u'CumulusCI-Test-master/src',
                u'unmanaged': True,
                u'zip_url': u'https://github.com/SalesforceFoundation/CumulusCI-Test/archive/master.zip',
            },
            {
                u'headers': {u'Authorization': u'token password'},
                u'namespace_inject': 'ccitest',
                u'namespace_strip': None,
                u'namespace_tokenize': None,
                u'subfolder': u'CumulusCI-Test-master/unpackaged/post/post',
                u'unmanaged': True,
                u'zip_url': u'https://github.com/SalesforceFoundation/CumulusCI-Test/archive/master.zip',
            },
        ])
Ejemplo n.º 25
0
 def setUp(self):
     self.api_version = 42.0
     self.global_config = BaseGlobalConfig(
         {"project": {
             "api_version": self.api_version
         }})
     self.tmpdir = tempfile.mkdtemp(dir=".")
     apex_path = os.path.join(self.tmpdir, "test.apex")
     with open(apex_path, "w") as f:
         f.write('System.debug("from file")')
     self.task_config = TaskConfig()
     self.task_config.config["options"] = {
         "path": apex_path,
         "apex": 'system.debug("Hello World!")',
         "namespaced": True,
         "param1": "StringValue",
     }
     self.project_config = BaseProjectConfig(self.global_config,
                                             config={"noyaml": True})
     self.project_config.config = {
         "project": {
             "package": {
                 "namespace": "abc",
                 "api_version": self.api_version
             }
         }
     }
     keychain = BaseProjectKeychain(self.project_config, "")
     self.project_config.set_keychain(keychain)
     self.org_config = OrgConfig(
         {
             "id": "foo/1",
             "instance_url": "https://example.com",
             "access_token": "abc123",
         },
         "test",
     )
     self.base_tooling_url = "{}/services/data/v{}/tooling/".format(
         self.org_config.instance_url, self.api_version)
Ejemplo n.º 26
0
    def setUp(self):
        self.global_config = BaseGlobalConfig()
        self.project_config = BaseProjectConfig(self.global_config,
                                                config={"noyaml": True})

        keychain = BaseProjectKeychain(self.project_config, "")
        self.project_config.set_keychain(keychain)

        self._task_log_handler.reset()
        self.task_log = self._task_log_handler.messages
        self.base_command = "sfdx force:mdapi:deploy --wait {}".format(
            CreateConnectedApp.deploy_wait)
        self.label = "Test_Label"
        self.username = "******"
        self.email = "TestUser@Email"
        self.task_config = TaskConfig({
            "options": {
                "label": self.label,
                "username": self.username,
                "email": self.email,
            }
        })
Ejemplo n.º 27
0
    def test_run_task(self):
        with temporary_dir() as path:
            xml_path = os.path.join(path, "test.xml")
            with open(xml_path, "w") as f:
                f.write("<root><todelete /></root>")

            project_config = BaseProjectConfig(BaseGlobalConfig())
            task_config = TaskConfig({
                "options": {
                    "elements": [{
                        "path": "test.xml",
                        "xpath": "./todelete"
                    }],
                    "chdir": path,
                }
            })
            task = RemoveElementsXPath(project_config, task_config)
            task()
            with open(xml_path, "r") as f:
                result = f.read()
            self.assertEqual(
                '<?xml version="1.0" encoding="UTF-8"?>\n<root/>\n', result)
Ejemplo n.º 28
0
def _make_task(task_class, task_config):
    task_config = TaskConfig(task_config)
    global_config = BaseGlobalConfig()
    project_config = BaseProjectConfig(
        global_config,
        config={
            "noyaml": True,
            "project": {
                "package": {
                    "api_version": "46.0"
                }
            }
        },
    )
    keychain = BaseProjectKeychain(project_config, "")
    project_config.set_keychain(keychain)
    org_config = DummyOrgConfig(
        {
            "instance_url": "https://example.com",
            "access_token": "abc123"
        }, "test")
    return task_class(project_config, task_config, org_config)
Ejemplo n.º 29
0
 def setUp(self):
     self.api_version = 38.0
     self.global_config = BaseGlobalConfig(
         {'project': {'api_version': self.api_version}})
     self.task_config = TaskConfig()
     self.task_config.config['options'] = {
         'junit_output': 'results_junit.xml',
         'poll_interval': 1,
         'test_name_match': '%_TEST',
     }
     self.project_config = BaseProjectConfig(self.global_config)
     self.project_config.config['project'] = {'package': {
         'api_version': self.api_version}}
     keychain = BaseProjectKeychain(self.project_config, '')
     self.project_config.set_keychain(keychain)
     self.org_config = OrgConfig({
         'id': 'foo/1',
         'instance_url': 'example.com',
         'access_token': 'abc123',
     }, 'test')
     self.base_tooling_url = 'https://{}/services/data/v{}/tooling/'.format(
         self.org_config.instance_url, self.api_version)
Ejemplo n.º 30
0
 def setUp(self):
     self.api_version = 42.0
     self.global_config = BaseGlobalConfig(
         {"project": {"api_version": self.api_version}}
     )
     self.task_config = TaskConfig()
     self.task_config.config["options"] = {
         "class_name": "ADDR_Seasonal_BATCH",
         "poll_interval": 1,
     }
     self.project_config = BaseProjectConfig(self.global_config)
     self.project_config.config["project"] = {
         "package": {"api_version": self.api_version}
     }
     keychain = BaseProjectKeychain(self.project_config, "")
     self.project_config.set_keychain(keychain)
     self.org_config = OrgConfig(
         {"id": "foo/1", "instance_url": "example.com", "access_token": "abc123"},
         "test",
     )
     self.base_tooling_url = "https://{}/services/data/v{}/tooling/".format(
         self.org_config.instance_url, self.api_version
     )