Skip to content

Commit 40754ac

Browse files
authored
Fix graphql API for fpbase-py (#400)
* working * use actual tests * no frozen
1 parent dbc8e57 commit 40754ac

File tree

2 files changed

+98
-5
lines changed

2 files changed

+98
-5
lines changed

backend/proteins/schema/query.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,9 @@ def resolve_opticalConfig(self, info, **kwargs):
143143
return gdo.query(models.OpticalConfig.objects.filter(id=_id), info).get()
144144
return None
145145

146-
dyes = graphene.List(types.Dye)
147-
dye = graphene.Field(types.Dye, id=graphene.Int(), name=graphene.String())
146+
dyes = graphene.List(types.DyeState)
147+
dye = graphene.Field(types.DyeState, id=graphene.Int(), name=graphene.String())
148148

149-
# FIXME:
150-
# "dye" is now returning a DyeState, not a Dye... this is backwards compatible
151-
# but incorrect and needs to be fixed with a deprecation cycle.
152149
def resolve_dyes(self, info, **kwargs):
153150
return gdo.query(models.DyeState.objects.all(), info)
154151

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""Run fpbasepy's test suite against our live server with seeded test data."""
2+
3+
import os
4+
import subprocess
5+
6+
import pytest
7+
8+
from proteins.factories import (
9+
CameraFactory,
10+
DyeStateFactory,
11+
FilterFactory,
12+
LightFactory,
13+
MicroscopeFactory,
14+
OpticalConfigFactory,
15+
ProteinFactory,
16+
create_egfp,
17+
)
18+
from proteins.models import Filter
19+
20+
FPBASEPY_REPO = "https://github.com/tlambert03/fpbasepy"
21+
22+
23+
@pytest.fixture
24+
def seed_fpbasepy_data(db):
25+
"""Seed database with data expected by fpbasepy tests."""
26+
# Proteins expected by tests
27+
create_egfp()
28+
ProteinFactory(
29+
name="mScarlet-I",
30+
default_state__name="default",
31+
default_state__ex_max=569,
32+
default_state__em_max=593,
33+
default_state__ext_coeff=104000,
34+
default_state__qy=0.54,
35+
)
36+
ProteinFactory(
37+
name="mEos3.2",
38+
default_state__name="default",
39+
default_state__ex_max=507,
40+
default_state__em_max=516,
41+
default_state__ext_coeff=63400,
42+
default_state__qy=0.84,
43+
)
44+
# Additional proteins for pdb test
45+
ProteinFactory(name="Clover1.5")
46+
ProteinFactory(name="6C")
47+
ProteinFactory(name="dClover2 A206K")
48+
49+
# Dye expected by tests
50+
DyeStateFactory(dye__name="Alexa Fluor 488", name="default")
51+
52+
# Filters expected by tests
53+
FilterFactory(name="Chroma ET525/50m", subtype=Filter.BPM)
54+
FilterFactory(name="Semrock FF01-520/35", subtype=Filter.BP)
55+
56+
# Camera and light source
57+
CameraFactory(name="Andor Zyla 5.5")
58+
LightFactory(name="Lumencor Celesta UV")
59+
60+
# Microscope with optical configs
61+
scope = MicroscopeFactory(name="Example Simple Widefield", id="wKqWbgApvguSNDSRZNSfpN")
62+
ex_filter = FilterFactory(name="Chroma ET470/40x", subtype=Filter.BPX)
63+
bs_filter = FilterFactory(name="Chroma T495lpxr", subtype=Filter.LP)
64+
em_filter = FilterFactory(name="Chroma ET525/50m-2", subtype=Filter.BPM)
65+
oc = OpticalConfigFactory(name="Widefield Green", microscope=scope)
66+
oc.filters.add(ex_filter, through_defaults={"path": "EX"})
67+
oc.filters.add(bs_filter, through_defaults={"path": "BS"})
68+
oc.filters.add(em_filter, through_defaults={"path": "EM"})
69+
70+
71+
@pytest.mark.django_db(transaction=True)
72+
def test_fpbasepy_upstream_suite(live_server, tmp_path, seed_fpbasepy_data):
73+
"""Clone and run fpbasepy's test suite against our GraphQL API."""
74+
repo = tmp_path / "fpbasepy"
75+
76+
# Clone and install
77+
subprocess.run(["git", "clone", "--depth=1", FPBASEPY_REPO, str(repo)], check=True)
78+
env = {k: v for k, v in os.environ.items() if k != "UV_FROZEN"}
79+
subprocess.run(["uv", "sync", "--extra", "test", "-q"], cwd=repo, env=env, check=True)
80+
81+
# Patch URL to point at live server
82+
(repo / "tests" / "conftest.py").write_text(f"""\
83+
import fpbase._fetch
84+
fpbase._fetch.FPbaseClient._FPbaseClient__instance = fpbase._fetch.FPbaseClient(
85+
base_url="{live_server.url}/graphql/"
86+
)
87+
""")
88+
89+
# Run tests (exclude test_get_missing_protein - it tests fpbasepy's fuzzy matching)
90+
env = {k: v for k, v in os.environ.items() if not k.startswith(("VIRTUAL_ENV", "DJANGO"))}
91+
result = subprocess.run(
92+
["uv", "run", "pytest", "tests", "-v", "-s", "-k", "not test_get_missing"],
93+
cwd=repo,
94+
env=env,
95+
)
96+
assert result.returncode == 0, "fpbasepy test suite failed"

0 commit comments

Comments
 (0)