@@ -327,6 +327,79 @@ def test_fpkgi_feed_multi_file_rom(
327327 assert response .status_code == status .HTTP_400_BAD_REQUEST
328328
329329
330+ def test_fpkgi_feed_names_are_unique_within_a_rom (
331+ client : TestClient , access_token : str , platform : Platform , rom : Rom
332+ ):
333+ platform = db_platform_handler .update_platform (
334+ platform .id , {"name" : "PlayStation 4" , "slug" : UPS .PS4 , "fs_slug" : UPS .PS4 }
335+ )
336+ rom = db_rom_handler .update_rom (
337+ rom .id ,
338+ {
339+ "platform_id" : platform .id ,
340+ "name" : "Test PS4" ,
341+ "fs_name" : "Test PS4" ,
342+ "fs_name_no_tags" : "Test PS4" ,
343+ "fs_name_no_ext" : "Test PS4" ,
344+ "fs_extension" : "" ,
345+ "fs_path" : f"{ platform .slug } /roms" ,
346+ "fs_size_bytes" : 369 ,
347+ "regions" : ["US" ],
348+ },
349+ )
350+ for sub_path , file_name , category in (
351+ ("" , "Test PS4 base.pkg" , None ),
352+ ("update" , "Test PS4 patch.pkg" , RomFileCategory .UPDATE ),
353+ ("dlc" , "Test PS4 brawler.pkg" , RomFileCategory .DLC ),
354+ ("dlc" , "Test PS4 loadout.pkg" , RomFileCategory .DLC ),
355+ # Same file name in two categories, so the file name alone is ambiguous
356+ ("dlc" , "Test PS4 extra.pkg" , RomFileCategory .DLC ),
357+ ("demo" , "Test PS4 extra.pkg" , RomFileCategory .DEMO ),
358+ ("demo" , "Test PS4 trial.pkg" , RomFileCategory .DEMO ),
359+ ):
360+ db_rom_handler .add_rom_file (
361+ RomFile (
362+ rom_id = rom .id ,
363+ file_name = file_name ,
364+ file_path = f"{ rom .fs_path } /{ rom .fs_name } /{ sub_path } " .rstrip ("/" ),
365+ file_size_bytes = 123 ,
366+ category = category ,
367+ )
368+ )
369+
370+ response = client .get (
371+ "/api/feeds/fpkgi/ps4" ,
372+ headers = {"Authorization" : f"Bearer { access_token } " },
373+ )
374+ assert response .status_code == status .HTTP_200_OK
375+
376+ data = response .json ()["DATA" ]
377+ assert len (data ) == 7
378+ assert sorted (entry ["name" ] for entry in data .values ()) == [
379+ "Test PS4 - DLC - Test PS4 extra" ,
380+ "Test PS4 - Demo - Test PS4 extra" ,
381+ "Test PS4 - Test PS4 base" ,
382+ "Test PS4 - Test PS4 brawler" ,
383+ "Test PS4 - Test PS4 loadout" ,
384+ "Test PS4 - Test PS4 trial" ,
385+ "Test PS4 - Update" ,
386+ ]
387+
388+ # Filtering must not change the name a package is served under
389+ response = client .get (
390+ "/api/feeds/fpkgi/ps4?content_type=dlc" ,
391+ headers = {"Authorization" : f"Bearer { access_token } " },
392+ )
393+ assert response .status_code == status .HTTP_200_OK
394+
395+ dlc_data = response .json ()["DATA" ]
396+ assert sorted (entry ["name" ] for entry in dlc_data .values ()) == [
397+ "Test PS4 - DLC - Test PS4 extra" ,
398+ "Test PS4 - Test PS4 brawler" ,
399+ "Test PS4 - Test PS4 loadout" ,
400+ ]
401+
402+
330403def test_kekatsu_feed (
331404 client : TestClient , access_token : str , platform : Platform , rom : Rom
332405):
0 commit comments