@@ -446,7 +446,7 @@ def test_dref_is_published(self):
446446 )
447447 url = f'/api/v2/dref/{ dref .id } /'
448448 data = {
449- "title" : "New Update Title"
449+ "title" : "New Update Title"
450450 }
451451 self .client .force_authenticate (self .user )
452452 response = self .client .patch (url , data )
@@ -795,3 +795,55 @@ def test_dref_for_assessment_report(self):
795795 response = self .client .post (url , data )
796796 self .assertEqual (response .status_code , 201 )
797797 self .assertEqual (Dref .objects .count (), old_count + 1 )
798+
799+ def test_dref_for_super_user (self ):
800+ user1 = UserFactory .create (
801+ 802+ first_name = 'Test' ,
803+ last_name = 'User1' ,
804+ password = 'admin123' ,
805+ 806+ is_superuser = True ,
807+ )
808+ user2 = UserFactory .create (
809+ 810+ first_name = 'Test' ,
811+ last_name = 'User2' ,
812+ password = 'admin123' ,
813+ 814+ )
815+ user3 = UserFactory .create (
816+ 817+ first_name = 'Test' ,
818+ last_name = 'User3' ,
819+ password = 'admin123' ,
820+ 821+ )
822+ dref1 = DrefFactory .create (
823+ title = 'Test Title' ,
824+ created_by = user2 ,
825+ )
826+ DrefFactory .create (
827+ title = 'Test Title New' ,
828+ )
829+
830+ # authenticate with user1(superuser)
831+ # user1 should be able to view all dref
832+ url = '/api/v2/dref/'
833+ self .client .force_authenticate (user1 )
834+ response = self .client .get (url )
835+ self .assertEqual (response .status_code , 200 )
836+ self .assertEqual (len (response .data ['results' ]), 2 )
837+
838+ # authenticate with User2
839+ self .client .force_authenticate (user2 )
840+ response = self .client .get (url )
841+ self .assertEqual (response .status_code , 200 )
842+ self .assertEqual (len (response .data ['results' ]), 1 )
843+ self .assertEqual (response .data ['results' ][0 ]['id' ], dref1 .id )
844+
845+ # authenticate with User3
846+ self .client .force_authenticate (user3 )
847+ response = self .client .get (url )
848+ self .assertEqual (response .status_code , 200 )
849+ self .assertEqual (len (response .data ['results' ]), 0 )
0 commit comments