41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
import shutil
|
|
|
|
import admin_analytics.config as config
|
|
from admin_analytics.config import UD_UNITID
|
|
from admin_analytics.ipeds.institution import load_institutions
|
|
|
|
|
|
def test_load_institutions_filters_to_ud(db_conn, fixtures_dir, tmp_path):
|
|
"""HD loader should only load UD's row when unitid_filter is set."""
|
|
ipeds_dir = tmp_path / "ipeds" / "hd" / "2023"
|
|
ipeds_dir.mkdir(parents=True)
|
|
shutil.copy(fixtures_dir / "hd2023.csv", ipeds_dir / "hd2023.csv")
|
|
|
|
original = config.IPEDS_DATA_DIR
|
|
config.IPEDS_DATA_DIR = tmp_path / "ipeds"
|
|
try:
|
|
count = load_institutions(db_conn, range(2023, 2024), unitid_filter=UD_UNITID)
|
|
finally:
|
|
config.IPEDS_DATA_DIR = original
|
|
|
|
assert count == 1
|
|
rows = db_conn.execute("SELECT * FROM raw_institution").fetchall()
|
|
assert len(rows) == 1
|
|
assert rows[0][0] == UD_UNITID
|
|
assert rows[0][3] == "University of Delaware"
|
|
|
|
|
|
def test_load_institutions_no_filter(db_conn, fixtures_dir, tmp_path):
|
|
"""Without filter, all institutions should load."""
|
|
ipeds_dir = tmp_path / "ipeds" / "hd" / "2023"
|
|
ipeds_dir.mkdir(parents=True)
|
|
shutil.copy(fixtures_dir / "hd2023.csv", ipeds_dir / "hd2023.csv")
|
|
|
|
original = config.IPEDS_DATA_DIR
|
|
config.IPEDS_DATA_DIR = tmp_path / "ipeds"
|
|
try:
|
|
count = load_institutions(db_conn, range(2023, 2024), unitid_filter=None)
|
|
finally:
|
|
config.IPEDS_DATA_DIR = original
|
|
|
|
assert count == 2
|