@@ -419,11 +419,12 @@ def test_user_can_save_valid_data_successfully(self, json_manager_with_schema) -
419419
420420 GIVEN: A user has valid data that conforms to the schema
421421 WHEN: They call save_json_data() with the data and directory
422- THEN: The data should be validated and saved successfully
422+ THEN: The data should be validated, saved successfully, and cached internally
423423 """
424424 # Arrange: Valid data and directory
425425 valid_data = {"name" : "Test Output" , "count" : 42 }
426426 data_dir = "/output/directory"
427+ json_manager_with_schema .data = None # Start with empty cache
427428
428429 with (
429430 patch .object (json_manager_with_schema , "validate_json_against_schema" , return_value = (True , "" )),
@@ -445,18 +446,23 @@ def test_user_can_save_valid_data_successfully(self, json_manager_with_schema) -
445446 assert error_message == ""
446447 mock_file .assert_called_once_with ("/output/directory/output.json" , "w" , encoding = "utf-8" , newline = "\n " )
447448 mock_dumps .assert_called_once_with (valid_data , indent = 4 )
449+ # Assert: Internal cache updated immediately (regression test for commit ccc53bb)
450+ assert json_manager_with_schema .data == valid_data
451+ assert json_manager_with_schema .data is valid_data
448452
449453 def test_user_cannot_save_invalid_data (self , json_manager_with_schema ) -> None :
450454 """
451455 User receives error when trying to save data that fails schema validation.
452456
453457 GIVEN: A user has data that doesn't conform to the schema
454458 WHEN: They call save_json_data()
455- THEN: The save should fail with validation error and no file operations
459+ THEN: The save should fail with validation error, no file operations, and cache unchanged
456460 """
457- # Arrange: Invalid data missing required field
461+ # Arrange: Invalid data missing required field and existing cache
462+ original_data = {"name" : "Original Config" , "count" : 50 }
458463 invalid_data = {"count" : 42 } # Missing required "name" field
459464 data_dir = "/output/directory"
465+ json_manager_with_schema .data = original_data
460466
461467 with (
462468 patch .object (
@@ -474,6 +480,8 @@ def test_user_cannot_save_invalid_data(self, json_manager_with_schema) -> None:
474480 assert "Missing required field" in error_message
475481 mock_file .assert_not_called ()
476482 mock_error .assert_called_once ()
483+ assert json_manager_with_schema .data == original_data
484+ assert json_manager_with_schema .data is not invalid_data
477485
478486 def test_user_handles_missing_directory_error (self , json_manager_with_schema ) -> None :
479487 """
0 commit comments