def test_init_options__namespace_injection(): pc = create_project_config(namespace="ns") org_config = DummyOrgConfig({"namespace": "ns"}) org_config._installed_packages = {"ns": None} task = create_task(ProfileGrantAllAccess, {}, project_config=pc, org_config=org_config) assert task.options["namespace_inject"] == "ns" assert task.options["namespaced_org"] assert task.options["managed"]
def test_validate_and_inject_mapping_queries_is_person_account_field(self): mock_describe_calls() mapping = parse_from_yaml( StringIO( ( "Insert Accounts:\n sf_object: Account\n table: Account\n fields:\n - Description__c\n" "Insert Contacts:\n sf_object: Contact\n table: Contact\n lookups:\n AccountId:\n table: Account" ) ) ) org_config = DummyOrgConfig( {"instance_url": "https://example.com", "access_token": "abc123"}, "test" ) validate_and_inject_mapping( mapping=mapping, org_config=org_config, namespace=None, data_operation=DataOperationType.QUERY, inject_namespaces=False, drop_missing=True, org_has_person_accounts_enabled=True, ) assert "Insert Accounts" in mapping assert "Insert Contacts" in mapping assert "IsPersonAccount" in mapping["Insert Accounts"]["fields"] assert "IsPersonAccount" in mapping["Insert Contacts"]["fields"]
def test_validate_and_inject_mapping_throws_exception_required_lookup_dropped(self): mock_describe_calls() # This test uses a bit of gimmickry to validate exception behavior on dropping a required lookup. # Since mapping_parser identifies target objects via the `table` clause rather than the actual schema, # which makes us resilient to polymorphic lookups, we'll pretend the non-nillable `Id` field is a lookup. mapping = parse_from_yaml( StringIO( ( "Insert Accounts:\n sf_object: NotAccount\n table: Account\n fields:\n - Nonsense__c\n" "Insert Contacts:\n sf_object: Contact\n table: Contact\n lookups:\n Id:\n table: Account" ) ) ) org_config = DummyOrgConfig( {"instance_url": "https://example.com", "access_token": "abc123"}, "test" ) with pytest.raises(BulkDataException): validate_and_inject_mapping( mapping=mapping, org_config=org_config, namespace=None, data_operation=DataOperationType.INSERT, inject_namespaces=False, drop_missing=True, )
def test_validate_and_inject_mapping_removes_lookups_with_drop_missing(self): mock_describe_calls() mapping = parse_from_yaml( StringIO( ( "Insert Accounts:\n sf_object: NotAccount\n table: Account\n fields:\n - Nonsense__c\n" "Insert Contacts:\n sf_object: Contact\n table: Contact\n lookups:\n AccountId:\n table: Account" ) ) ) org_config = DummyOrgConfig( {"instance_url": "https://example.com", "access_token": "abc123"}, "test" ) validate_and_inject_mapping( mapping=mapping, org_config=org_config, namespace=None, data_operation=DataOperationType.INSERT, inject_namespaces=False, drop_missing=True, ) assert "Insert Accounts" not in mapping assert "Insert Contacts" in mapping assert "AccountId" not in mapping["Insert Contacts"].lookups
def test_validate_and_inject_mapping_works_case_insensitively(self): mock_describe_calls() mapping = parse_from_yaml( StringIO( ( "Insert Accounts:\n sf_object: account\n table: account\n fields:\n - name\n" "Insert Contacts:\n sf_object: contact\n table: contact\n fields:\n - fIRSTnAME\n lookups:\n accountid:\n table: account" ) ) ) org_config = DummyOrgConfig( {"instance_url": "https://example.com", "access_token": "abc123"}, "test" ) assert mapping["Insert Accounts"].sf_object != "Account" assert mapping["Insert Accounts"].sf_object == "account" assert "name" in mapping["Insert Accounts"].fields assert "Name" not in mapping["Insert Accounts"].fields validate_and_inject_mapping( mapping=mapping, org_config=org_config, namespace=None, data_operation=DataOperationType.INSERT, inject_namespaces=False, drop_missing=False, ) assert mapping["Insert Accounts"].sf_object == "Account" assert mapping["Insert Accounts"].sf_object != "account" assert "Name" in mapping["Insert Accounts"].fields assert "name" not in mapping["Insert Accounts"].fields
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 fallback_orgconfig(): return DummyOrgConfig( { "instance_url": "https://orgname.salesforce.com", "access_token": "pytest_sf_orgconnect_abc123", "id": "ORGID/ORGID", }, "pytest_sf_orgconnect_dummy_orgconfig", )
def _create_task(self, task_config=None): if not task_config: task_config = {} return MergeBranch( project_config=self.project_config, task_config=TaskConfig(task_config), org_config=DummyOrgConfig(), )
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 _make_task(task_class, task_config): task_config = TaskConfig(task_config) global_config = BaseGlobalConfig() project_config = BaseProjectConfig(global_config) org_config = DummyOrgConfig( { 'instance_url': 'example.com', 'access_token': 'abc123', }, 'test') return task_class(project_config, task_config, org_config)
def _create_task(self, task_config=None, org_config=None): if not task_config: task_config = {} if not org_config: org_config = {} task = BaseTask( project_config=self.project_config, task_config=TaskConfig(task_config), org_config=DummyOrgConfig(org_config), ) return 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_validate_and_inject_mapping_enforces_fls(self): mock_describe_calls() mapping = parse_from_yaml( StringIO( "Insert Accounts:\n sf_object: Account\n table: Account\n fields:\n - Nonsense__c" ) ) org_config = DummyOrgConfig( {"instance_url": "https://example.com", "access_token": "abc123"}, "test" ) with pytest.raises(BulkDataException): validate_and_inject_mapping( mapping=mapping, org_config=org_config, namespace=None, data_operation=DataOperationType.INSERT, inject_namespaces=False, drop_missing=False, )
def test_validate_and_inject_mapping_removes_namespaces(self): mock_describe_calls() # Note: History__c is a mock field added to our stored, mock describes (in JSON) ms = parse_from_yaml( StringIO( """Insert Accounts: sf_object: Account table: Account fields: - ns__History__c""" ) )["Insert Accounts"] org_config = DummyOrgConfig( {"instance_url": "https://example.com", "access_token": "abc123"}, "test" ) assert ms.validate_and_inject_namespace( org_config, "ns", DataOperationType.INSERT, inject_namespaces=True ) assert list(ms.fields.keys()) == ["History__c"]