def setUp(self): self.universal_config = UniversalConfig() self.project_config = BaseProjectConfig(self.universal_config, config={"noyaml": True}) self.task_config = TaskConfig() self._task_log_handler.reset() self.task_log = self._task_log_handler.messages
def test_fetch(self): project_config = BaseProjectConfig(UniversalConfig()) with temporary_dir() as d: touch("cumulusci.yml") source = LocalFolderSource(project_config, {"path": d}) project_config = source.fetch() assert project_config.repo_root == os.path.realpath(d)
def test_run_task(self): src_path = os.path.join(__location__, "package_metadata", "namespaced_report_folder") with open(os.path.join(src_path, "package.xml"), "r") as f: expected = f.read() with temporary_dir() as path: output_path = os.path.join(path, "package.xml") project_config = BaseProjectConfig( UniversalConfig(), { "project": { "package": { "name": "Test Package", "api_version": "36.0" } } }, ) task_config = TaskConfig({ "options": { "path": src_path, "output": output_path, "managed": True } }) org_config = OrgConfig({}, "test") task = UpdatePackageXml(project_config, task_config, org_config) task() with open(output_path, "r") as f: result = f.read() self.assertEqual(expected, result)
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")) with cd(self.tempdir_project): universal_config = UniversalConfig() with self.assertRaises(ProjectConfigNotFound): BaseProjectConfig(universal_config)
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.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, } } )
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.api_version = 42.0 self.universal_config = UniversalConfig( {"project": {"api_version": self.api_version}} ) self.task_config = TaskConfig() self.project_config = BaseProjectConfig( self.universal_config, config={"noyaml": True} ) 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 = DummyOrgConfig( { "id": "foo/1", "instance_url": "https://example.com", "access_token": "abc123", }, "test", ) self.base_normal_url = "{}/services/data/v{}/query/".format( self.org_config.instance_url, self.api_version ) self.task_log = self._task_log_handler.messages
def setUp(self): os.mkdir(os.path.join(self.tempdir, ".git")) self.universal_config = UniversalConfig() self.project_config = BaseProjectConfig(self.universal_config, config={"noyaml": True}) self.org_config = OrgConfig({}, "test") self.task_config = TaskConfig({})
def test_run_task(self): with temporary_dir() as d: os.mkdir(".git") os.mkdir("src") meta_xml_path = os.path.join(d, "src", "test-meta.xml") with open(meta_xml_path, "w") as f: f.write("""<?xml version="1.0" encoding="UTF-8"?> <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>1.0</apiVersion> </ApexClass> """) project_config = BaseProjectConfig(UniversalConfig(), config={"noyaml": True}) task_config = TaskConfig({"options": {"version": "43.0"}}) task = UpdateApi(project_config, task_config) task() with open(meta_xml_path, "r") as f: result = f.read() self.assertEqual( """<?xml version="1.0" encoding="UTF-8"?> <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>43.0</apiVersion> </ApexClass> """, result, )
def setUp(self): self.api_version = 42.0 self.universal_config = UniversalConfig( {"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.universal_config, config={"noyaml": True} ) 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": "https://example.com", "access_token": "abc123", }, "test", ) self.base_tooling_url = "{}/services/data/v{}/tooling/".format( self.org_config.instance_url, self.api_version ) self.task_log = self._task_log_handler.messages
def test_get_package_zip(self, CreatePackageZipBuilder): project_config = BaseProjectConfig( UniversalConfig(), {"project": {"package": {"name": "TestPackage", "api_version": "43.0"}}}, ) task = create_task(CreatePackage, project_config=project_config) task._get_package_zip() CreatePackageZipBuilder.assert_called_once()
def test_load_universal_config_no_local(self, mock_class): mock_class.return_value = self.tempdir_home # clear cache UniversalConfig.config = None config = UniversalConfig() with open(__location__ + "/../../cumulusci.yml", "r") as f_expected_config: expected_config = yaml.safe_load(f_expected_config) self.assertEqual(config.config, expected_config)
def test_load_universal_config_empty_local(self, mock_class): self._create_universal_config_local("") mock_class.return_value = self.tempdir_home config = UniversalConfig() with open(__location__ + "/../../cumulusci.yml", "r") as f_expected_config: expected_config = yaml.safe_load(f_expected_config) self.assertEqual(config.config, expected_config)
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_run_task(self): with temporary_dir() as d: os.mkdir(".git") os.mkdir("src") meta_xml_path = os.path.join(d, "src", "test-meta.xml") with open(meta_xml_path, "w") as f: f.write("""<?xml version="1.0" encoding="UTF-8"?> <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <packageVersions> <namespace>npsp</namespace> <majorNumber>1</majorNumber> <minorNumber>0</minorNumber> </packageVersions> <packageVersions> <namespace>npe01</namespace> <majorNumber>1</majorNumber> <minorNumber>0</minorNumber> </packageVersions> </ApexClass> """) project_config = BaseProjectConfig(UniversalConfig(), config={"noyaml": True}) project_config.get_static_dependencies = mock.Mock(return_value=[{ "namespace": "npsp", "version": "3.0", "dependencies": [{ "namespace": "npe01", "version": "1.1" }], }]) task_config = TaskConfig() task = UpdateDependencies(project_config, task_config) task() with open(meta_xml_path, "r") as f: result = f.read() self.assertEqual( """<?xml version="1.0" encoding="UTF-8"?> <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <packageVersions> <namespace>npsp</namespace> <majorNumber>3</majorNumber> <minorNumber>0</minorNumber> </packageVersions> <packageVersions> <namespace>npe01</namespace> <majorNumber>1</majorNumber> <minorNumber>1</minorNumber> </packageVersions> </ApexClass> """, result, )
def test_run_task__revert_path_not_found(self): project_config = BaseProjectConfig(UniversalConfig(), config={"noyaml": True}) task_config = TaskConfig( {"options": { "path": "bogus", "revert_path": "bogus" }}) task = RevertManagedSrc(project_config, task_config) with self.assertRaises(TaskOptionsError): task()
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() with cd(self.tempdir_project): universal_config = UniversalConfig() config = BaseProjectConfig(universal_config) self.assertEqual(config.repo_commit, self.current_commit)
def test_run_task__revert_path_already_exists(self): with temporary_dir() as path, temporary_dir() as revert_path: project_config = BaseProjectConfig(UniversalConfig(), config={"noyaml": True}) task_config = TaskConfig( {"options": { "path": path, "revert_path": revert_path }}) task = CreateManagedSrc(project_config, task_config) with self.assertRaises(TaskOptionsError): task()
def _make_task(task_class, task_config): task_config = TaskConfig(task_config) universal_config = UniversalConfig() project_config = BaseProjectConfig( universal_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)
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, BaseProjectConfig.config_filename) content = "" self._write_file(filename, content) with cd(self.tempdir_project): universal_config = UniversalConfig() config = BaseProjectConfig(universal_config) self.assertEqual(config.config_project, {})
def setUp(self): self.universal_config = UniversalConfig() self.project_config = BaseProjectConfig(self.universal_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()
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.project_config.keychain.set_service( "github", ServiceConfig({ "username": "******", "password": "******", "email": "*****@*****.**", }), )
def test_load_universal_config_with_local(self, mock_class): local_yaml = "tasks:\n newtesttask:\n description: test description" self._create_universal_config_local(local_yaml) mock_class.return_value = self.tempdir_home # clear cache UniversalConfig.config = None config = UniversalConfig() with open(__location__ + "/../../cumulusci.yml", "r") as f_expected_config: expected_config = yaml.safe_load(f_expected_config) expected_config["tasks"]["newtesttask"] = {} expected_config["tasks"]["newtesttask"]["description"] = "test description" self.assertEqual(config.config, expected_config)
def create_project_config(repo_name="TestRepo", repo_owner="TestOwner", repo_commit=None): universal_config = UniversalConfig() project_config = DummyProjectConfig( universal_config=universal_config, repo_name=repo_name, repo_owner=repo_owner, repo_commit=repo_commit, config=copy.deepcopy(universal_config.config), ) keychain = BaseProjectKeychain(project_config, None) project_config.set_keychain(keychain) return project_config
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_universal_config_local(local_yaml) # create valid project config file self._create_project_config() with cd(self.tempdir_project): universal_config = UniversalConfig() config = BaseProjectConfig(universal_config) self.assertEqual(config.project__package__name, "TestProject") self.assertEqual(config.project__package__namespace, "testproject")
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" with cd(self.tempdir_project): universal_config = UniversalConfig() config = BaseProjectConfig(universal_config, additional_yaml=content) self.assertNotEqual(config.config_additional_yaml, {}) self.assertEqual(config.project__package__api_version, 45.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(UniversalConfig(), config={"noyaml": True}) task_config = TaskConfig( {"options": { "path": path, "revert_path": revert_path }}) task = RevertManagedSrc(project_config, task_config) task() self.assertTrue(os.path.exists(os.path.join(path, "file")))
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": "******", "token": "TestPass", "email": "*****@*****.**", }), )
def test_run_task(self, remove_xml_element_directory): with temporary_dir() as path: revert_path = os.path.join(os.path.dirname(path), os.path.basename(path) + "_revert") project_config = BaseProjectConfig(UniversalConfig(), config={"noyaml": True}) task_config = TaskConfig( {"options": { "path": path, "revert_path": revert_path }}) task = CreateUnmanagedEESrc(project_config, task_config) task() remove_xml_element_directory.assert_has_calls([ mock.call("availableFields", path, "*.object"), mock.call("visibility[.='Protected']", path, "*.object"), ])
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