from pathlib import Path import pytest from pingcap_datapipelines.outbound_config import OutboundConfig, load_outbound_config def test_repository_month_end_arr_config_resolves_sql_and_safe_batch_size() -> None: path = Path(__file__).parents[1] / "configs" / "jobs" / "month_end_arr_outbound.yaml" config = load_outbound_config(path) assert config.name == "month_end_arr_outbound" assert config.source_query_path.name == "month_end_arr.sql" assert config.source_query_path.is_file() assert config.location == "us-west2" assert config.batch_size == 200 assert config.nexuscrm_object == "Month_End_ARR__c" assert config.nexuscrm_external_id_field == "Outbound_Key__c" def test_external_id_must_not_be_duplicated_in_required_fields(tmp_path: Path) -> None: query = tmp_path / "source.sql" query.write_text("SELECT 1") config_path = tmp_path / "job.yaml" config_path.write_text( """ job: name: example source: project: example query_file: source.sql target: base_url: https://example.test object: Example__c external_id_field: Key__c required_fields: [Key__c] state: dataset: control """ ) with pytest.raises(ValueError, match="must not also appear"): load_outbound_config(config_path) def test_outbound_config_defaults_to_us_location() -> None: config = OutboundConfig( path=Path("job.yaml"), data={ "job": {"name": "example"}, "source": {"project": "example", "query_file": "source.sql"}, "target": {"base_url": "https://example.test", "object": "Example__c", "external_id_field": "Key__c"}, "state": {"dataset": "control"}, }, ) assert config.location == "US"