File size: 1,538 Bytes
8ff1a92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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"