@@ -29,6 +29,7 @@ def test_secret_key_too_short(self) -> None:
2929 assert "SECRET_KEY must be at least 32 characters long" in errors [0 ]["msg" ]
3030
3131 def test_secret_key_default_placeholder (self ) -> None :
32+ # These should always fail
3233 test_cases = ["your_secret_key_here" , "default_secret_key" ]
3334
3435 for placeholder in test_cases :
@@ -40,6 +41,24 @@ def test_secret_key_default_placeholder(self) -> None:
4041 assert len (errors ) == 1
4142 assert errors [0 ]["loc" ] == ("SECRET_KEY" ,)
4243 assert "SECRET_KEY must not use default placeholder values" in errors [0 ]["msg" ]
44+
45+ def test_secret_key_change_me_without_testing (self ) -> None :
46+ # CHANGE_ME should fail when not in testing mode
47+ with mock .patch .dict (os .environ , {"SECRET_KEY" : "CHANGE_ME_this_is_a_dev_key_min_32_chars_required" , "TESTING" : "false" }, clear = True ):
48+ with pytest .raises (ValidationError ) as exc_info :
49+ Settings ()
50+
51+ errors = exc_info .value .errors ()
52+ assert len (errors ) == 1
53+ assert errors [0 ]["loc" ] == ("SECRET_KEY" ,)
54+ assert "CHANGE_ME detected" in errors [0 ]["msg" ]
55+
56+ def test_secret_key_change_me_with_testing (self ) -> None :
57+ # CHANGE_ME should be allowed in testing mode
58+ with mock .patch .dict (os .environ , {"SECRET_KEY" : "CHANGE_ME_this_is_a_dev_key_min_32_chars_required" , "TESTING" : "true" }, clear = True ):
59+ settings = Settings ()
60+ assert settings .SECRET_KEY == "CHANGE_ME_this_is_a_dev_key_min_32_chars_required"
61+ assert settings .TESTING is True
4362
4463 def test_secret_key_valid (self ) -> None :
4564 valid_key = "a" * 32 # 32 character key
0 commit comments