diff --git a/backend/tests/handler/filesystem/test_firmware_handler.py b/backend/tests/handler/filesystem/test_firmware_handler.py index ab6981840..23143be1b 100644 --- a/backend/tests/handler/filesystem/test_firmware_handler.py +++ b/backend/tests/handler/filesystem/test_firmware_handler.py @@ -138,16 +138,38 @@ class TestFSFirmwareHandler: assert hasattr(handler, "stream_file") assert hasattr(handler, "exclude_single_files") - def test_firmware_path_construction(self, handler: FSFirmwareHandler, config): - """Test that firmware paths are constructed correctly""" + def test_firmware_path_construction_structure_a( + self, handler: FSFirmwareHandler, config + ): + """Test that firmware paths are constructed correctly for Structure A""" platform_fs_slug = "n64" with patch( "handler.filesystem.firmware_handler.cm.get_config", return_value=config ): - # Test normal path (high prio doesn't exist) - path = handler.get_firmware_fs_structure(platform_fs_slug) - assert path == f"{platform_fs_slug}/{config.FIRMWARE_FOLDER_NAME}" + with patch( + "handler.filesystem.firmware_handler.glob.glob", return_value=[] + ): + path = handler.get_firmware_fs_structure(platform_fs_slug) + assert path == f"{config.FIRMWARE_FOLDER_NAME}/{platform_fs_slug}" + + def test_firmware_path_construction_structure_b( + self, handler: FSFirmwareHandler, config + ): + """Test that firmware paths are constructed correctly for Structure B""" + platform_fs_slug = "n64" + + with patch( + "handler.filesystem.firmware_handler.cm.get_config", return_value=config + ): + with patch( + "handler.filesystem.firmware_handler.glob.glob", + return_value=[ + f"{LIBRARY_BASE_PATH}/{platform_fs_slug}/{config.ROMS_FOLDER_NAME}" + ], + ): + path = handler.get_firmware_fs_structure(platform_fs_slug) + assert path == f"{platform_fs_slug}/{config.FIRMWARE_FOLDER_NAME}" async def test_multiple_platform_handling(self, handler: FSFirmwareHandler, config): """Test handling of different platform slugs""" diff --git a/backend/tests/handler/filesystem/test_platforms_handler.py b/backend/tests/handler/filesystem/test_platforms_handler.py index 091305a06..a302cabc3 100644 --- a/backend/tests/handler/filesystem/test_platforms_handler.py +++ b/backend/tests/handler/filesystem/test_platforms_handler.py @@ -86,77 +86,98 @@ class TestFSPlatformsHandler: result = handler._exclude_platforms(platforms) assert result == platforms - def test_get_platforms_directory_high_priority_structure( + def test_get_platforms_directory_structure_a( self, handler: FSPlatformsHandler, config ): - """Test get_platforms_directory with high priority structure""" + """Test get_platforms_directory with Structure A (roms/{platform})""" with patch( "handler.filesystem.platforms_handler.cm.get_config", return_value=config ): - with patch("os.path.exists", return_value=True): + with patch( + "handler.filesystem.platforms_handler.glob.glob", return_value=[] + ): result = handler.get_platforms_directory() assert result == config.ROMS_FOLDER_NAME - def test_get_platforms_directory_normal_structure( + def test_get_platforms_directory_structure_b( self, handler: FSPlatformsHandler, config ): - """Test get_platforms_directory with normal structure""" + """Test get_platforms_directory with Structure B ({platform}/roms)""" with patch( "handler.filesystem.platforms_handler.cm.get_config", return_value=config ): - with patch("os.path.exists", return_value=False): + with patch( + "handler.filesystem.platforms_handler.glob.glob", + return_value=[f"{LIBRARY_BASE_PATH}/n64/{config.ROMS_FOLDER_NAME}"], + ): result = handler.get_platforms_directory() assert result == "" - def test_get_platform_fs_structure_high_priority( + def test_get_platform_fs_structure_structure_a( self, handler: FSPlatformsHandler, config ): - """Test get_platform_fs_structure with high priority structure""" + """Test get_platform_fs_structure with Structure A (roms/{platform})""" fs_slug = "n64" with patch( "handler.filesystem.platforms_handler.cm.get_config", return_value=config ): - with patch("os.path.exists", return_value=True): + with patch( + "handler.filesystem.platforms_handler.glob.glob", return_value=[] + ): result = handler.get_platform_fs_structure(fs_slug) assert result == f"{config.ROMS_FOLDER_NAME}/{fs_slug}" - def test_get_platform_fs_structure_normal_structure( + def test_get_platform_fs_structure_structure_b( self, handler: FSPlatformsHandler, config ): - """Test get_platform_fs_structure with normal structure""" + """Test get_platform_fs_structure with Structure B ({platform}/roms)""" fs_slug = "n64" with patch( "handler.filesystem.platforms_handler.cm.get_config", return_value=config ): - result = handler.get_platform_fs_structure(fs_slug) - assert result == f"{fs_slug}/{config.ROMS_FOLDER_NAME}" + with patch( + "handler.filesystem.platforms_handler.glob.glob", + return_value=[ + f"{LIBRARY_BASE_PATH}/{fs_slug}/{config.ROMS_FOLDER_NAME}" + ], + ): + result = handler.get_platform_fs_structure(fs_slug) + assert result == f"{fs_slug}/{config.ROMS_FOLDER_NAME}" def test_get_platform_fs_structure_custom_folder_name( self, handler: FSPlatformsHandler, config_custom_folder ): - """Test get_platform_fs_structure with custom folder name""" + """Test get_platform_fs_structure with custom folder name (Structure B)""" fs_slug = "psx" with patch( "handler.filesystem.platforms_handler.cm.get_config", return_value=config_custom_folder, ): - result = handler.get_platform_fs_structure(fs_slug) - assert result == f"{fs_slug}/{config_custom_folder.ROMS_FOLDER_NAME}" + with patch( + "handler.filesystem.platforms_handler.glob.glob", + return_value=[ + f"{LIBRARY_BASE_PATH}/{fs_slug}/{config_custom_folder.ROMS_FOLDER_NAME}" + ], + ): + result = handler.get_platform_fs_structure(fs_slug) + assert result == f"{fs_slug}/{config_custom_folder.ROMS_FOLDER_NAME}" async def test_add_platform_creates_directory( self, handler: FSPlatformsHandler, config ): - """Test that add_platform creates the correct directory""" + """Test that add_platform creates the correct directory (Structure A)""" fs_slug = "gba" expected_path = f"{config.ROMS_FOLDER_NAME}/{fs_slug}" with patch( "handler.filesystem.platforms_handler.cm.get_config", return_value=config ): - with patch("os.path.exists", return_value=True): + with patch( + "handler.filesystem.platforms_handler.glob.glob", return_value=[] + ): with patch.object(handler, "make_directory") as mock_make_directory: await handler.add_platform(fs_slug) mock_make_directory.assert_called_once_with(expected_path) @@ -164,14 +185,19 @@ class TestFSPlatformsHandler: async def test_add_platform_normal_structure( self, handler: FSPlatformsHandler, config ): - """Test that add_platform creates directory with normal structure""" + """Test that add_platform creates directory with Structure B""" fs_slug = "gba" expected_path = f"{fs_slug}/{config.ROMS_FOLDER_NAME}" with patch( "handler.filesystem.platforms_handler.cm.get_config", return_value=config ): - with patch("os.path.exists", return_value=False): + with patch( + "handler.filesystem.platforms_handler.glob.glob", + return_value=[ + f"{LIBRARY_BASE_PATH}/{fs_slug}/{config.ROMS_FOLDER_NAME}" + ], + ): with patch.object(handler, "make_directory") as mock_make_directory: await handler.add_platform(fs_slug) mock_make_directory.assert_called_once_with(expected_path) @@ -207,7 +233,9 @@ class TestFSPlatformsHandler: with patch( "handler.filesystem.platforms_handler.cm.get_config", return_value=config ): - with patch("os.path.exists", return_value=True): + with patch( + "handler.filesystem.platforms_handler.glob.glob", return_value=[] + ): with patch.object( handler, "list_directories", return_value=[] ) as mock_list: diff --git a/backend/tests/handler/filesystem/test_roms_handler.py b/backend/tests/handler/filesystem/test_roms_handler.py index f393006b5..a882827a0 100644 --- a/backend/tests/handler/filesystem/test_roms_handler.py +++ b/backend/tests/handler/filesystem/test_roms_handler.py @@ -102,8 +102,8 @@ class TestFSRomsHandler: """Test that FSRomsHandler initializes with LIBRARY_BASE_PATH""" assert handler.base_path == Path(LIBRARY_BASE_PATH).resolve() - def test_get_roms_fs_structure_normal_structure(self, handler: FSRomsHandler): - """Test get_roms_fs_structure with normal structure""" + def test_get_roms_fs_structure_structure_b(self, handler: FSRomsHandler): + """Test get_roms_fs_structure with Structure B ({platform}/roms)""" fs_slug = "n64" with pytest.MonkeyPatch.context() as m: @@ -122,15 +122,16 @@ class TestFSRomsHandler: FIRMWARE_FOLDER_NAME="bios", ), ) - m.setattr("os.path.exists", lambda x: False) # Simulate normal structure + m.setattr( + "handler.filesystem.roms_handler.glob.glob", + lambda _: [f"{LIBRARY_BASE_PATH}/{fs_slug}/roms"], + ) result = handler.get_roms_fs_structure(fs_slug) assert result == f"{fs_slug}/roms" - def test_get_roms_fs_structure_high_priority_structure( - self, handler: FSRomsHandler - ): - """Test get_roms_fs_structure with high priority structure""" + def test_get_roms_fs_structure_structure_a(self, handler: FSRomsHandler): + """Test get_roms_fs_structure with Structure A (roms/{platform})""" fs_slug = "n64" with pytest.MonkeyPatch.context() as m: @@ -149,9 +150,7 @@ class TestFSRomsHandler: FIRMWARE_FOLDER_NAME="bios", ), ) - m.setattr( - "os.path.exists", lambda x: True - ) # Simulate high priority structure + m.setattr("handler.filesystem.roms_handler.glob.glob", lambda _: []) result = handler.get_roms_fs_structure(fs_slug) assert result == f"roms/{fs_slug}" @@ -521,12 +520,16 @@ class TestFSRomsHandler: non_hashable_platform.fs_slug = "n64" non_hashable_platform.slug = "nintendo-64" - # Test ROM file structure paths - hashable_path = handler.get_roms_fs_structure(hashable_platform.fs_slug) - non_hashable_path = handler.get_roms_fs_structure(non_hashable_platform.fs_slug) - with pytest.MonkeyPatch.context() as m: - m.setattr("os.path.exists", lambda x: False) # Normal structure + m.setattr( + "handler.filesystem.roms_handler.glob.glob", + lambda _: [f"{LIBRARY_BASE_PATH}/n64/roms"], + ) # Structure B + + hashable_path = handler.get_roms_fs_structure(hashable_platform.fs_slug) + non_hashable_path = handler.get_roms_fs_structure( + non_hashable_platform.fs_slug + ) assert hashable_path == f"{hashable_platform.fs_slug}/roms" assert non_hashable_path == f"{non_hashable_platform.fs_slug}/roms" @@ -553,14 +556,17 @@ class TestFSRomsHandler: fs_slug = "gba" with pytest.MonkeyPatch.context() as m: - # Test with normal structure - m.setattr("os.path.exists", lambda x: False) + # Test with Structure B + m.setattr( + "handler.filesystem.roms_handler.glob.glob", + lambda _: [f"{LIBRARY_BASE_PATH}/{fs_slug}/roms"], + ) structure = handler.get_roms_fs_structure(fs_slug) assert structure == f"{fs_slug}/roms" - # Test with high priority structure - m.setattr("os.path.exists", lambda x: True) + # Test with Structure A + m.setattr("handler.filesystem.roms_handler.glob.glob", lambda _: []) structure = handler.get_roms_fs_structure(fs_slug) assert structure == f"roms/{fs_slug}"