Skip to content

Commit 1979c1d

Browse files
authored
fixes FPBASE-6H7 (#402)
* fixes FPBASE-6H7 * type ignore
1 parent 80d33ec commit 1979c1d

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

backend/proteins/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class CameraAdmin(SpectrumOwner, VersionAdmin):
225225
class SpectrumAdminForm(forms.ModelForm):
226226
"""Custom form to handle the Spectrum.data property in admin."""
227227

228-
data = forms.CharField(
228+
data = forms.CharField( # type: ignore[assignment]
229229
widget=forms.Textarea(attrs={"rows": 10, "cols": 80}),
230230
required=False,
231231
help_text="Spectrum data as [[wavelength, value], ...] pairs",

backend/proteins/views/protein.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
def check_switch_type(object, request):
6666
suggested = suggested_switch_type(object)
6767
if suggested and object.switch_type != suggested:
68-
disp = dict(Protein.SwitchingChoices).get(suggested).lower()
68+
disp = dict(Protein.SwitchingChoices.choices).get(suggested).lower()
6969
actual = object.get_switch_type_display().lower()
7070
msg = (
7171
"<i class='fa fa-exclamation-circle me-2'></i><strong>Warning:</strong> "
@@ -683,7 +683,7 @@ def problems_inconsistencies(request):
683683
for prot in p:
684684
suggestion = suggested_switch_type(prot)
685685
if (prot.switch_type or suggestion) and (prot.switch_type != suggestion):
686-
bad_switch.append((prot, dict(Protein.SwitchingChoices).get(suggestion)))
686+
bad_switch.append((prot, dict(Protein.SwitchingChoices.choices).get(suggestion)))
687687

688688
return render(
689689
request,

backend/tests/test_proteins/test_views.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,56 @@ def test_scope_report_json_full_workflow_integration(self, client):
465465
# Verify fluors dict contains our fluorophores
466466
assert state.slug in data["fluors"], f"State {state.slug} missing from fluors"
467467
assert dye_state.slug in data["fluors"], f"DyeState {dye_state.slug} missing from fluors"
468+
469+
470+
class TestProteinSubmitMultiState(TestCase):
471+
"""Regression tests for FPBASE-6H7: protein submission with multiple states."""
472+
473+
def setUp(self) -> None:
474+
self.admin_user = User.objects.create_superuser(
475+
username="admin", email="[email protected]", password="password"
476+
)
477+
478+
def test_protein_submit_with_two_states(self):
479+
"""Test protein submission with multiple states doesn't raise ValueError.
480+
481+
Regression test for FPBASE-6H7: When a protein has 2+ states but no transitions,
482+
the check_switch_type function is called and previously crashed with ValueError
483+
due to incorrect dict(Protein.SwitchingChoices) usage.
484+
"""
485+
self.client.login(username="admin", password="password")
486+
initial_count = Protein.objects.count()
487+
488+
# Submit protein with 2 states (no transitions) - triggers check_switch_type
489+
# with suggested switch_type='o' (OTHER)
490+
response = self.client.post(
491+
reverse("proteins:submit"),
492+
data={
493+
"name": "MultiStateProtein",
494+
"reference_doi": "10.1038/nmeth.2413",
495+
# Two states, no transitions = triggers 'OTHER' suggestion
496+
"states-0-name": "on",
497+
"states-0-ex_max": 488,
498+
"states-0-em_max": 525,
499+
"states-1-name": "off",
500+
"states-1-ex_max": 400,
501+
"states-1-em_max": 450,
502+
"confirmation": True,
503+
"lineage-TOTAL_FORMS": 1,
504+
"lineage-INITIAL_FORMS": 0,
505+
"lineage-MIN_NUM_FORMS": 0,
506+
"lineage-MAX_NUM_FORMS": 1,
507+
"states-TOTAL_FORMS": 2,
508+
"states-INITIAL_FORMS": 0,
509+
"states-MIN_NUM_FORMS": 0,
510+
"states-MAX_NUM_FORMS": 1000,
511+
},
512+
)
513+
514+
# Should redirect to protein detail (success), not error
515+
assert response.status_code == 302
516+
assert Protein.objects.count() == initial_count + 1
517+
518+
new_prot = cast("Protein", Protein.objects.get(name="MultiStateProtein"))
519+
assert response.url == new_prot.get_absolute_url()
520+
assert new_prot.states.count() == 2

0 commit comments

Comments
 (0)