def test_process_github_dependency_no_unpackaged(self): global_config = BaseGlobalConfig() config = BaseProjectConfig(global_config) github = self._make_github() del github.repositories["CumulusCI-Test"]._contents["unpackaged/pre"] del github.repositories["CumulusCI-Test"]._contents["unpackaged/post"] config.get_github_api = mock.Mock(return_value=github) config.keychain = DummyKeychain() result = config.process_github_dependency( { "github": "https://github.com/SFDO-Tooling/CumulusCI-Test.git", "unmanaged": True, } ) self.assertEqual( result, [ { u"name": "Install CumulusCI-Test-Dep 2.0", u"version": "2.0", u"namespace": "ccitestdep", }, { u"name": "Deploy CumulusCI-Test", u"repo_owner": "SFDO-Tooling", u"repo_name": "CumulusCI-Test", u"ref": "commit_sha", u"subfolder": u"src", u"unmanaged": True, u"namespace_inject": None, u"namespace_strip": None, u"namespace_tokenize": None, }, ], )
def test_process_github_dependency_with_tag(self): global_config = BaseGlobalConfig() config = BaseProjectConfig(global_config) github = self._make_github() github.repositories["CumulusCI-Test"]._releases = [ DummyRelease("release/1.0", "1.0") ] config.get_github_api = mock.Mock(return_value=github) config.keychain = DummyKeychain() result = config.process_github_dependency( { "github": "https://github.com/SFDO-Tooling/CumulusCI-Test.git", "tag": "release/1.0", } ) self.assertIn( { "name": "Install CumulusCI-Test 1.0", "namespace": "ccitest", "version": "1.0", "dependencies": [ { "name": "Install CumulusCI-Test-Dep 2.0", "namespace": "ccitestdep", "version": "2.0", } ], }, result, )
def test_init_sentry(self, raven_client): config = BaseProjectConfig(BaseGlobalConfig()) config.keychain = mock.Mock() config.init_sentry() self.assertEqual( {"repo", "commit", "cci version", "branch"}, set(raven_client.call_args[1]["tags"].keys()), )
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( BaseGlobalConfig(), 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 _make_task(task_class, task_config): task_config = TaskConfig(task_config) global_config = BaseGlobalConfig() project_config = BaseProjectConfig(global_config, config={"noyaml": True}) 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_get_version_for_tag_invalid_beta(self): config = BaseProjectConfig( BaseGlobalConfig(), { "project": { "git": {"prefix_beta": "beta/", "prefix_release": "release/"} } }, ) self.assertEqual(None, config.get_version_for_tag("beta/invalid-format"))
def test_get_version_for_tag(self): config = BaseProjectConfig( BaseGlobalConfig(), { "project": { "git": {"prefix_beta": "beta/", "prefix_release": "release/"} } }, ) self.assertEqual("1.0", config.get_version_for_tag("release/1.0"))
class TestSalesforceToolingTask(unittest.TestCase): 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, config={"noyaml": True} ) self.project_config.config["project"] = { "package": {"api_version": self.api_version} } self.project_config.config["services"] = { "connectedapp": {"attributes": {"client_id": {}}} } self.keychain = BaseProjectKeychain(self.project_config, "") self.project_config.set_keychain(self.keychain) self.task_config = TaskConfig() self.org_config = OrgConfig( {"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 ) def test_get_tooling_object(self): task = BaseSalesforceApiTask( self.project_config, self.task_config, self.org_config ) task._init_task() obj = task._get_tooling_object("TestObject") url = self.base_tooling_url + "sobjects/TestObject/" self.assertEqual(obj.base_url, url) def test_default_client_name(self): task = BaseSalesforceApiTask( self.project_config, self.task_config, self.org_config ) task._init_task() self.assertIn("Sforce-Call-Options", task.sf.headers) self.assertIn("CumulusCI/", task.sf.headers["Sforce-Call-Options"]) def test_connected_app_client_name(self): self.project_config.keychain.set_service( "connectedapp", ServiceConfig({"client_id": "test123"}) ) task = BaseSalesforceApiTask( self.project_config, self.task_config, self.org_config ) task._init_task() self.assertIn("Sforce-Call-Options", task.sf.headers) self.assertNotIn("CumulusCI/", task.sf.headers["Sforce-Call-Options"]) self.assertIn("test123", task.sf.headers["Sforce-Call-Options"])
def test_process_github_dependency_cannot_find_latest(self): global_config = BaseGlobalConfig() config = BaseProjectConfig(global_config) config.keychain = DummyKeychain() github = self._make_github() github.repositories["CumulusCI-Test-Dep"]._releases = [] config.get_github_api = mock.Mock(return_value=github) with self.assertRaises(DependencyResolutionError): config.process_github_dependency( {"github": "https://github.com/SFDO-Tooling/CumulusCI-Test-Dep.git"} )
def test_get_previous_version(self): config = BaseProjectConfig( BaseGlobalConfig(), { "project": { "git": {"prefix_beta": "beta/", "prefix_release": "release/"} } }, ) config.get_github_api = mock.Mock(return_value=self._make_github()) result = config.get_previous_version() self.assertEqual("1.0", result)
def test_get_latest_tag_beta(self): config = BaseProjectConfig( BaseGlobalConfig(), { "project": { "git": {"prefix_beta": "beta/", "prefix_release": "release/"} } }, ) config.get_github_api = mock.Mock(return_value=self._make_github()) result = config.get_latest_tag(beta=True) self.assertEqual("beta/1.0-Beta_2", result)
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)
def test_process_github_dependency_tag_not_found(self): global_config = BaseGlobalConfig() config = BaseProjectConfig(global_config) config.keychain = DummyKeychain() config.get_github_api = mock.Mock(return_value=self._make_github()) with self.assertRaises(DependencyResolutionError): config.process_github_dependency( { "github": "https://github.com/SFDO-Tooling/CumulusCI-Test-Dep.git", "tag": "bogus", } )
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, )
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, 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 )
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, } } )
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"]))
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 = BaseGlobalConfig() config = BaseProjectConfig(global_config) self.assertEqual(config.repo_commit, self.current_commit)
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, )
def test_create_scratch_org(self): project_config = BaseProjectConfig(self.global_config, {"orgs": { "scratch": { "dev": {} } }}) keychain = self.keychain_class(project_config, self.key) keychain.set_org = mock.Mock() keychain.create_scratch_org("test", "dev", days=3) org_config = keychain.set_org.call_args[0][0] self.assertEqual(3, org_config.days)
def setUp(self): self.global_config = BaseGlobalConfig() self.project_config = BaseProjectConfig( self.global_config, config={"noyaml": True} ) self.task_config = TaskConfig() keychain = BaseProjectKeychain(self.project_config, "") self.project_config.set_keychain(keychain) self._task_log_handler.reset() self.task_log = self._task_log_handler.messages
def test_repo_commit_packed_refs(self): config = BaseProjectConfig(BaseGlobalConfig()) with temporary_dir() as d: os.system("git init") with open(os.path.join(d, ".git", "packed-refs"), "w") as f: f.write("# pack-refs with: peeled fully-peeled sorted\n") f.write("#\n") f.write( "8ce67f4519190cd1ec9785105168e21b9599bc27 refs/remotes/origin/master\n" ) self.assertIsNotNone(config.repo_commit)
def test_repo_branch(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_branch, self.current_branch)
def test_sources(self, 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.assertFalse("dummy1" in sys.path) self.assertFalse("dummy2" in sys.path) task() project_config.get_namespace.assert_has_calls( [mock.call("test1"), mock.call("test2")]) self.assertTrue("dummy1" in sys.path) self.assertTrue("dummy2" in sys.path)
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', }, ])
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, } })
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)
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)
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)
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 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) os.chdir(self.tempdir_project) global_config = BaseGlobalConfig() config = BaseProjectConfig(global_config) self.assertEqual(config.config_project, {})
def setUp(self): self.global_config = BaseGlobalConfig() self.project_config = BaseProjectConfig(self.global_config, config={"noyaml": True}) self.task_config = TaskConfig() self._task_log_handler.reset() self.task_log = self._task_log_handler.messages self.Popen = MockPopen() self.r = Replacer() self.r.replace("cumulusci.tasks.command.subprocess.Popen", self.Popen) self.addCleanup(self.r.restore)
def setUp(self): self.project_config = BaseProjectConfig(BaseGlobalConfig(), get_base_config()) self.project_config.config["project"]["package"]["namespace"] = "npsp" self.project_config.config["project"]["dependencies"] = [ {"namespace": "nochangedep", "version": "1.0"}, {"namespace": "changedep", "version": "1.1"}, ] keychain = BaseProjectKeychain(self.project_config, "") keychain.set_service( "mrbelvedere", ServiceConfig({"base_url": "http://mrbelvedere", "api_key": "1234"}), ) self.project_config.set_keychain(keychain) self.task_config = TaskConfig({"options": {"tag": "beta/1.0-Beta_2"}})
def test_repo_info_missing_env(self): env = { "CUMULUSCI_AUTO_DETECT": "1", "HEROKU_TEST_RUN_ID": "TEST1", "HEROKU_TEST_RUN_BRANCH": "master", "HEROKU_TEST_RUN_COMMIT_VERSION": "HEAD", "CUMULUSCI_REPO_BRANCH": "feature/test", "CUMULUSCI_REPO_COMMIT": "HEAD~1", "CUMULUSCI_REPO_ROOT": ".", } with mock.patch.dict(os.environ, env): with self.assertRaises(ConfigError): config = BaseProjectConfig(BaseGlobalConfig()) config.repo_info
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()) task_config = TaskConfig( {"options": { "path": path, "revert_path": revert_path }}) task = CreateUnmanagedEESrc(project_config, task_config) task() removeXmlElement.assert_called_once_with("availableFields", path, "*.object")
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 )
def test_get_package_zip(self, CreatePackageZipBuilder): project_config = BaseProjectConfig( BaseGlobalConfig(), { "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_run_task(self): with temporary_dir() as revert_path: with open(os.path.join(revert_path, "file"), "w") as f: pass path = os.path.join(os.path.dirname(revert_path), os.path.basename(revert_path) + "_orig") project_config = BaseProjectConfig(BaseGlobalConfig()) 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")))
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 = BaseGlobalConfig() config = BaseProjectConfig(global_config) self.assertEqual(config.project__package__name, "TestProject") self.assertEqual(config.project__package__namespace, "testproject")
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 )
def setUp(self): self.project_config = BaseProjectConfig(BaseGlobalConfig(), get_base_config()) self.project_config.config["project"]["package"]["namespace"] = "npsp" self.project_config.config["project"]["dependencies"] = [ { "namespace": "nochangedep", "version": "1.0" }, { "namespace": "changedep", "version": "1.1" }, ] keychain = BaseProjectKeychain(self.project_config, "") keychain.set_service( "mrbelvedere", ServiceConfig({ "base_url": "http://mrbelvedere", "api_key": "1234" }), ) self.project_config.set_keychain(keychain) self.task_config = TaskConfig({"options": {"tag": "beta/1.0-Beta_2"}})
def setUp(self): self.api_version = 36.0 self.universal_config = UniversalConfig( {"project": {"package": {"api_version": self.api_version}}} ) self.project_config = BaseProjectConfig( self.universal_config, config={"noyaml": True} ) self.project_config.config["project"] = { "package": {"api_version": self.api_version} } self.project_config.config["services"] = { "connectedapp": {"attributes": {"client_id": {}}} } self.keychain = BaseProjectKeychain(self.project_config, "") self.project_config.set_keychain(self.keychain) self.task_config = TaskConfig() self.org_config = OrgConfig( {"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 )
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 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": {} } }, "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._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)
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'
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 = BaseGlobalConfig() config = BaseProjectConfig(global_config, additional_yaml=content) self.assertNotEqual(config.config_additional_yaml, {}) self.assertEqual(config.project__package__api_version, 10)
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, )
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)
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
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, config={"noyaml": True} ) self.project_config.config["project"] = { "package": {"api_version": self.api_version} } self.project_config.config["services"] = { "connectedapp": {"attributes": {"client_id": {}}} } self.keychain = BaseProjectKeychain(self.project_config, "") self.project_config.set_keychain(self.keychain) self.task_config = TaskConfig() self.org_config = OrgConfig( {"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 )
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, '') app_config = ConnectedAppOAuthConfig() keychain.set_connected_app(app_config) self.project_config.set_keychain(keychain) self.org_config = OrgConfig({ 'id': 'foo/1', '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)
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, } 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 )
def test_repo_commit_from_repo_info(self): config = BaseProjectConfig(BaseGlobalConfig()) config._repo_info = {"commit": "abcdef"} self.assertEqual("abcdef", config.repo_commit)
def test_get_tag_for_version_beta(self): config = BaseProjectConfig( BaseGlobalConfig(), {"project": {"git": {"prefix_beta": "beta/"}}} ) self.assertEqual("beta/1.0-Beta_1", config.get_tag_for_version("1.0 (Beta 1)"))
def test_get_tag_for_version(self): config = BaseProjectConfig( BaseGlobalConfig(), {"project": {"git": {"prefix_release": "release/"}}} ) self.assertEqual("release/1.0", config.get_tag_for_version("1.0"))
def test_check_keychain(self): config = BaseProjectConfig(BaseGlobalConfig()) with self.assertRaises(KeychainNotFound): config._check_keychain()
def test_get_static_dependencies(self): dep = {"namespace": "npsp", "version": "3"} config = BaseProjectConfig( BaseGlobalConfig(), {"project": {"dependencies": [dep]}} ) self.assertEqual([dep], config.get_static_dependencies())
def test_get_static_dependencies_no_dependencies(self): config = BaseProjectConfig(BaseGlobalConfig()) self.assertEqual([], config.get_static_dependencies())
def test_use_sentry(self): config = BaseProjectConfig(BaseGlobalConfig()) config.keychain = mock.Mock() self.assertTrue(config.use_sentry)
def test_process_github_dependency_latest(self): global_config = BaseGlobalConfig() config = BaseProjectConfig(global_config) config.keychain = DummyKeychain() github = self._make_github() github.repositories["CumulusCI-Test-Dep"]._releases = [ DummyRelease("beta/1.1-Beta_1", "1.1 (Beta 1)"), DummyRelease("release/1.0", "1.0"), ] config.get_github_api = mock.Mock(return_value=github) result = config.process_github_dependency( { "github": "https://github.com/SFDO-Tooling/CumulusCI-Test.git", "unmanaged": True, "skip": ["unpackaged/pre/skip", "unpackaged/post/skip"], }, "", include_beta=True, ) self.assertEqual( result, [ { u"name": "Deploy unpackaged/pre/pre", u"repo_owner": "SFDO-Tooling", u"repo_name": "CumulusCI-Test", u"ref": "commit_sha", u"subfolder": u"unpackaged/pre/pre", u"unmanaged": True, u"namespace_inject": None, u"namespace_strip": None, u"namespace_tokenize": None, }, { u"name": "Install CumulusCI-Test-Dep 1.1 (Beta 1)", u"version": "1.1 (Beta 1)", u"namespace": "ccitestdep", }, { u"name": "Deploy CumulusCI-Test", u"repo_owner": "SFDO-Tooling", u"repo_name": "CumulusCI-Test", u"ref": "commit_sha", u"subfolder": u"src", u"unmanaged": True, u"namespace_inject": None, u"namespace_strip": None, u"namespace_tokenize": None, }, { u"name": "Deploy unpackaged/post/post", u"repo_owner": "SFDO-Tooling", u"repo_name": "CumulusCI-Test", u"ref": "commit_sha", u"subfolder": u"unpackaged/post/post", u"unmanaged": True, u"namespace_inject": "ccitest", u"namespace_strip": None, u"namespace_tokenize": None, }, ], )