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 _init_mapping(self): """Load a YAML mapping file.""" mapping_file_path = self.options["mapping"] if not mapping_file_path: raise TaskOptionsError("Mapping file path required") self.mapping = parse_from_yaml(mapping_file_path) validate_and_inject_mapping( mapping=self.mapping, org_config=self.org_config, namespace=self.project_config.project__package__namespace, data_operation=DataOperationType.INSERT, inject_namespaces=self.options["inject_namespaces"], drop_missing=self.options["drop_missing_schema"], )
def _init_mapping(self): """Load a YAML mapping file.""" mapping_file_path = self.options["mapping"] if not mapping_file_path: raise TaskOptionsError("Mapping file path required") self.logger.info(f"Mapping file: {self.options['mapping']}") self.mapping = parse_from_yaml(mapping_file_path) validate_and_inject_mapping( mapping=self.mapping, org_config=self.org_config, namespace=self.project_config.project__package__namespace, data_operation=DataOperationType.QUERY, inject_namespaces=self.options["inject_namespaces"], drop_missing=self.options["drop_missing_schema"], org_has_person_accounts_enabled=self.org_config. is_person_accounts_enabled, )
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, )