def convert_org_id_to_18(apps, schema_editor): """ Use 18-char IDs to better match the Salesforce API """ Job = apps.get_model("api", "Job") ScratchOrg = apps.get_model("api", "ScratchOrg") PreflightResult = apps.get_model("api", "PreflightResult") for org in ScratchOrg.objects.exclude(org_id__isnull=True): old_id = org.org_id new_id = convert_to_18(old_id) org.org_id = new_id org.save() Job.objects.filter(org_id=old_id).update(org_id=new_id) PreflightResult.objects.filter(org_id=old_id).update(org_id=new_id)
def test_create_scratch_org__no_preflight( self, settings, plan_factory, scratch_org_factory ): settings.DEVHUB_USERNAME = "******" plan = plan_factory() with ExitStack() as stack: stack.enter_context(patch("metadeploy.api.jobs.local_github_checkout")) jwt_session = stack.enter_context( patch("metadeploy.api.salesforce.jwt_session") ) jwt_session.return_value = { "instance_url": "https://sample.salesforce.org/", "access_token": "abc123", "refresh_token": "abc123", } OrgConfig = stack.enter_context( patch("metadeploy.api.salesforce.OrgConfig") ) OrgConfig.return_value = MagicMock( instance_url="https://sample.salesforce.org/", access_token="abc123", refresh_token="abc123", ) open = stack.enter_context(patch("metadeploy.api.salesforce.open")) fake_json = json.dumps({"edition": ""}) open.return_value = MagicMock( **{ "__enter__.return_value": MagicMock( **{"read.return_value": fake_json} ) } ) SimpleSalesforce = stack.enter_context( patch("metadeploy.api.salesforce.SimpleSalesforce") ) SimpleSalesforce.return_value = MagicMock( **{ "ScratchOrgInfo.get.return_value": { "LoginUrl": "https://sample.salesforce.org/", "ScratchOrg": "abc123", "SignupUsername": "******", "AuthCode": "abc123", } } ) OAuth2Client = stack.enter_context( patch("metadeploy.api.salesforce.OAuth2Client") ) OAuth2Client.return_value = MagicMock( **{ "auth_code_grant.return_value": MagicMock( **{ "json.return_value": { "access_token": "abc123", "refresh_token": "abc123", } } ) } ) BaseCumulusCI = stack.enter_context( patch("metadeploy.api.salesforce.BaseCumulusCI") ) org_config = MockDict() org_config.config_file = "/" BaseCumulusCI.return_value = MagicMock( **{ "project_config.repo_root": "/", "keychain.get_org.return_value": org_config, } ) stack.enter_context(patch("metadeploy.api.salesforce.DeployOrgSettings")) stack.enter_context( patch("cumulusci.core.flowrunner.PreflightFlowCoordinator.run") ) # Cheat the auto-triggering of the job by adding a fake # enqueued_at: scratch_org = scratch_org_factory( plan=plan, enqueued_at=datetime(2020, 9, 4, 12), ) create_scratch_org(scratch_org.id) scratch_org.refresh_from_db() assert scratch_org.expires_at == org_config.expires assert scratch_org.org_id == convert_to_18(org_config.org_id)