import pytest
from typing import Dict
from tempfile import NamedTemporaryFile

from backend.condition.lookups.uprn_lookup_csv import UprnLookupLocal


@pytest.fixture
def prop_ref_uprn_csv_file() -> str:
    csv_content = """reference,out_uprn
    ABC123,10000000001
    DEF456,10000000002
    GHI789,10000000003
    """
    with NamedTemporaryFile(mode="w+", delete=False, suffix=".csv") as tmp:
        tmp.write(csv_content)
        tmp.flush()
        return tmp.name


def test_generate_prop_ref_uprn_from_csv_file(prop_ref_uprn_csv_file: str) -> None:
    # arrange
    uprn_lookup = UprnLookupLocal(prop_ref_uprn_csv_file)
    expected_map: Dict[str, int] = {
        "ABC123": 10000000001,
        "DEF456": 10000000002,
        "GHI789": 10000000003,
    }

    # act
    actual_map: Dict[str, int] = uprn_lookup.get_property_ref_to_uprn_lookup()

    # assert
    assert actual_map == expected_map
