@@ -516,6 +516,18 @@ class DeniedViewWithDetailAND3(PermissionInstanceView):
516516 permission_classes = (BasicPermWithDetail & AnotherBasicPermWithDetail ,)
517517
518518
519+ class DeniedViewWithDetailOR1 (PermissionInstanceView ):
520+ permission_classes = (BasicPerm | BasicPermWithDetail ,)
521+
522+
523+ class DeniedViewWithDetailOR2 (PermissionInstanceView ):
524+ permission_classes = (BasicPermWithDetail | BasicPerm ,)
525+
526+
527+ class DeniedViewWithDetailOR3 (PermissionInstanceView ):
528+ permission_classes = (BasicPermWithDetail | AnotherBasicPermWithDetail ,)
529+
530+
519531class DeniedObjectView (PermissionInstanceView ):
520532 permission_classes = (BasicObjectPerm ,)
521533
@@ -536,6 +548,18 @@ class DeniedObjectViewWithDetailAND3(PermissionInstanceView):
536548 permission_classes = (AnotherBasicObjectPermWithDetail & BasicObjectPermWithDetail ,)
537549
538550
551+ class DeniedObjectViewWithDetailOR1 (PermissionInstanceView ):
552+ permission_classes = (BasicObjectPerm | BasicObjectPermWithDetail ,)
553+
554+
555+ class DeniedObjectViewWithDetailOR2 (PermissionInstanceView ):
556+ permission_classes = (BasicObjectPermWithDetail | BasicObjectPerm ,)
557+
558+
559+ class DeniedObjectViewWithDetailOR3 (PermissionInstanceView ):
560+ permission_classes = (BasicObjectPermWithDetail | AnotherBasicObjectPermWithDetail ,)
561+
562+
539563denied_view = DeniedView .as_view ()
540564
541565denied_view_with_detail = DeniedViewWithDetail .as_view ()
@@ -544,6 +568,10 @@ class DeniedObjectViewWithDetailAND3(PermissionInstanceView):
544568denied_view_with_detail_and_2 = DeniedViewWithDetailAND2 .as_view ()
545569denied_view_with_detail_and_3 = DeniedViewWithDetailAND3 .as_view ()
546570
571+ denied_view_with_detail_or_1 = DeniedViewWithDetailOR1 .as_view ()
572+ denied_view_with_detail_or_2 = DeniedViewWithDetailOR2 .as_view ()
573+ denied_view_with_detail_or_3 = DeniedViewWithDetailOR3 .as_view ()
574+
547575denied_object_view = DeniedObjectView .as_view ()
548576
549577denied_object_view_with_detail = DeniedObjectViewWithDetail .as_view ()
@@ -552,6 +580,10 @@ class DeniedObjectViewWithDetailAND3(PermissionInstanceView):
552580denied_object_view_with_detail_and_2 = DeniedObjectViewWithDetailAND2 .as_view ()
553581denied_object_view_with_detail_and_3 = DeniedObjectViewWithDetailAND3 .as_view ()
554582
583+ denied_object_view_with_detail_or_1 = DeniedObjectViewWithDetailOR1 .as_view ()
584+ denied_object_view_with_detail_or_2 = DeniedObjectViewWithDetailOR2 .as_view ()
585+ denied_object_view_with_detail_or_3 = DeniedObjectViewWithDetailOR3 .as_view ()
586+
555587
556588class CustomPermissionsTests (TestCase ):
557589 def setUp (self ):
@@ -593,6 +625,25 @@ def test_permission_denied_with_custom_detail_and_3(self):
593625 self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
594626 self .assertEqual (detail , CUSTOM_MESSAGE_1 )
595627
628+ def test_permission_denied_with_custom_detail_or_1 (self ):
629+ response = denied_view_with_detail_or_1 (self .request , pk = 1 )
630+ detail = response .data .get ('detail' )
631+ self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
632+ self .assertEqual (detail , CUSTOM_MESSAGE_1 )
633+
634+ def test_permission_denied_with_custom_detail_or_2 (self ):
635+ response = denied_view_with_detail_or_2 (self .request , pk = 1 )
636+ detail = response .data .get ('detail' )
637+ self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
638+ self .assertEqual (detail , CUSTOM_MESSAGE_1 )
639+
640+ def test_permission_denied_with_custom_detail_or_3 (self ):
641+ response = denied_view_with_detail_or_3 (self .request , pk = 1 )
642+ detail = response .data .get ('detail' )
643+ self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
644+ expected_message = '"{0}" OR "{1}"' .format (CUSTOM_MESSAGE_1 , CUSTOM_MESSAGE_2 )
645+ self .assertEqual (detail , expected_message )
646+
596647 def test_permission_denied_for_object (self ):
597648 response = denied_object_view (self .request , pk = 1 )
598649 detail = response .data .get ('detail' )
@@ -625,6 +676,25 @@ def test_permission_denied_for_object_with_custom_detail_and_3(self):
625676 self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
626677 self .assertEqual (detail , CUSTOM_MESSAGE_2 )
627678
679+ def test_permission_denied_for_object_with_custom_detail_or_1 (self ):
680+ response = denied_object_view_with_detail_or_1 (self .request , pk = 1 )
681+ detail = response .data .get ('detail' )
682+ self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
683+ self .assertEqual (detail , CUSTOM_MESSAGE_1 )
684+
685+ def test_permission_denied_for_object_with_custom_detail_or_2 (self ):
686+ response = denied_object_view_with_detail_or_2 (self .request , pk = 1 )
687+ detail = response .data .get ('detail' )
688+ self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
689+ self .assertEqual (detail , CUSTOM_MESSAGE_1 )
690+
691+ def test_permission_denied_for_object_with_custom_detail_or_3 (self ):
692+ response = denied_object_view_with_detail_or_3 (self .request , pk = 1 )
693+ detail = response .data .get ('detail' )
694+ self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
695+ expected_message = '"{0}" OR "{1}"' .format (CUSTOM_MESSAGE_1 , CUSTOM_MESSAGE_2 )
696+ self .assertEqual (detail , expected_message )
697+
628698
629699class PermissionsCompositionTests (TestCase ):
630700
0 commit comments