TOXRA.AI / tests /test_ctx_resolve.py
hchevva's picture
Upload 5 files
8ff1a92 verified
import asyncio
import httpx
from core.sources import ctx
def test_resolve_dtxsid_prefers_cas(monkeypatch):
async def fake_cas(q, http):
return "DTXSID1234567"
async def fake_name(q, http):
return None
async def fake_pc(q, http):
return "DTXSID0000000"
async def fake_dash(q, http):
return None
monkeypatch.setattr(ctx, "_resolve_from_cas", fake_cas)
monkeypatch.setattr(ctx, "_resolve_from_name", fake_name)
monkeypatch.setattr(ctx, "_resolve_dtxsid_via_pubchem", fake_pc)
monkeypatch.setattr(ctx, "_resolve_dtxsid_via_dashboard", fake_dash)
async def run():
async with httpx.AsyncClient() as client:
return await ctx.resolve_dtxsid("50-00-0", client)
assert asyncio.run(run()) == "DTXSID1234567"
def test_resolve_dtxsid_pubchem_fallback(monkeypatch):
async def fake_cas(q, http):
return None
async def fake_name(q, http):
return None
async def fake_pc(q, http):
return "DTXSID7654321"
async def fake_dash(q, http):
return None
monkeypatch.setattr(ctx, "_resolve_from_cas", fake_cas)
monkeypatch.setattr(ctx, "_resolve_from_name", fake_name)
monkeypatch.setattr(ctx, "_resolve_dtxsid_via_pubchem", fake_pc)
monkeypatch.setattr(ctx, "_resolve_dtxsid_via_dashboard", fake_dash)
async def run():
async with httpx.AsyncClient() as client:
return await ctx.resolve_dtxsid("formaldehyde", client)
assert asyncio.run(run()) == "DTXSID7654321"