@@ -576,3 +576,76 @@ def test_settings_touristic_content_category_no_picto(self):
576576 self .assertEqual (len (category_item ), TouristicContentCategory .objects .count ())
577577 self .assertEqual (category_item [0 ].get ("name" ), category .label )
578578 self .assertIsNone (category_item [0 ].get ("pictogram" ))
579+
580+ def test_settings_practice_portal_filtering (self ):
581+ """Test that practices are filtered by portal when portal parameter is provided"""
582+ # Create portals
583+ portal_a = common_factories .TargetPortalFactory ()
584+ portal_b = common_factories .TargetPortalFactory ()
585+
586+ # Create practices
587+ practice_a = trekking_factories .PracticeFactory ()
588+ practice_b = trekking_factories .PracticeFactory ()
589+ practice_c = trekking_factories .PracticeFactory ()
590+
591+ # Create treks with different portal configurations
592+ trek_portal_a = trekking_factories .TrekFactory .create (
593+ practice = practice_a , published_fr = True , portals = (portal_a ,)
594+ )
595+ trek_portal_b = trekking_factories .TrekFactory .create (
596+ practice = practice_b , published_fr = True , portals = (portal_b ,)
597+ )
598+ trek_no_portal = trekking_factories .TrekFactory .create (
599+ practice = practice_c , published_fr = True
600+ )
601+
602+ # Test without portal parameter - should include all practices
603+ response = self .get_settings ()
604+ self .assertEqual (response .status_code , 200 )
605+ json_response = response .json ()
606+ practice_item = next (
607+ (
608+ item .get ("values" )
609+ for item in json_response .get ("data" )
610+ if item ["id" ] == "practice"
611+ ),
612+ None ,
613+ )
614+ practice_names = [p .get ("name" ) for p in practice_item ]
615+ self .assertIn (practice_a .name , practice_names )
616+ self .assertIn (practice_b .name , practice_names )
617+ self .assertIn (practice_c .name , practice_names )
618+
619+ # Test with portal_a - should only include practice_a and practice_c (no portal constraint)
620+ response = self .get_settings ({"portal" : portal_a .name })
621+ self .assertEqual (response .status_code , 200 )
622+ json_response = response .json ()
623+ practice_item = next (
624+ (
625+ item .get ("values" )
626+ for item in json_response .get ("data" )
627+ if item ["id" ] == "practice"
628+ ),
629+ None ,
630+ )
631+ practice_names = [p .get ("name" ) for p in practice_item ]
632+ self .assertIn (practice_a .name , practice_names )
633+ self .assertNotIn (practice_b .name , practice_names )
634+ self .assertIn (practice_c .name , practice_names )
635+
636+ # Test with portal_b - should only include practice_b and practice_c (no portal constraint)
637+ response = self .get_settings ({"portal" : portal_b .name })
638+ self .assertEqual (response .status_code , 200 )
639+ json_response = response .json ()
640+ practice_item = next (
641+ (
642+ item .get ("values" )
643+ for item in json_response .get ("data" )
644+ if item ["id" ] == "practice"
645+ ),
646+ None ,
647+ )
648+ practice_names = [p .get ("name" ) for p in practice_item ]
649+ self .assertNotIn (practice_a .name , practice_names )
650+ self .assertIn (practice_b .name , practice_names )
651+ self .assertIn (practice_c .name , practice_names )
0 commit comments