@@ -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