@@ -88,3 +88,41 @@ def test_user_change_password(self):
8888 }, format = "json" )
8989 self .assertEqual (r .status_code , 400 , r .content [:1000 ])
9090 self .assertIn ("Update of password though API is not allowed" , r .content .decode ("utf-8" ))
91+
92+ def test_user_deactivate (self ):
93+ # user with good password
94+ password = "testTEST1234!@#$"
95+ r = self .client .post (reverse ("user-list" ), {
96+ "username" : "api-user-10" ,
97+ "email" : "admin@dojo.com" ,
98+ "password" : password ,
99+ }, format = "json" )
100+ self .assertEqual (r .status_code , 201 , r .content [:1000 ])
101+
102+ # user with good password
103+ password = "testTEST1234!@#$"
104+ r = self .client .post (reverse ("user-list" ), {
105+ "username" : "api-user-2" ,
106+ "email" : "admin@dojo.com" ,
107+ "password" : password ,
108+ }, format = "json" )
109+ self .assertEqual (r .status_code , 201 , r .content [:1000 ])
110+ user_id = r .json ()["id" ]
111+
112+ # deactivate
113+ r = self .client .patch ("{}{}/" .format (reverse ("user-list" ), user_id ), {
114+ "is_active" : False ,
115+ }, format = "json" )
116+ self .assertEqual (r .status_code , 200 , r .content [:1000 ])
117+
118+ # check is_active field
119+ r = self .client .get ("{}{}/" .format (reverse ("user-list" ), user_id ))
120+ self .assertEqual (r .status_code , 200 , r .content [:1000 ])
121+ self .assertEqual (r .json ()["is_active" ], False , r .content [:1000 ])
122+
123+ # API key retrieval should fail for inactive user
124+ r = self .client .post (reverse ("api-token-auth" ), {
125+ "username" : "api-user-2" ,
126+ "password" : password ,
127+ }, format = "json" )
128+ self .assertEqual (r .status_code , 400 , r .content [:1000 ])
0 commit comments